954,593 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

connect to an external site

M trying to connect to a site using the following code. But not able to. Please help

this.req = (HttpWebRequest)WebRequest.Create("http://wwwd.way2sms.com/auth.cl");
this.req.CookieContainer = new CookieContainer();
this.req.AllowAutoRedirect = false;
this.req.Method = "POST";
this.req.ContentType = "application/x-www-form-urlencoded";
this.strNewValue = "username=" + ckuser + "&password=" + ckpass;
this.req.ContentLength = this.strNewValue.Length;
StreamWriter writer = new StreamWriter(this.req.GetRequestStream(), Encoding.ASCII);
writer.Write(this.strNewValue);
writer.Close();
                
this.response = (HttpWebResponse)this.req.GetResponse();
this.cookieCntr = this.req.CookieContainer;
this.response.Close();
this.req = (HttpWebRequest)WebRequest.Create("http://wwwd.way2sms.com//jsp/InstantSMS.jsp?val=0");
                this.req.CookieContainer = this.cookieCntr;

this.req.Method = "GET";
this.response = (HttpWebResponse)this.req.GetResponse();

responseee = new StreamReader(this.response.GetResponseStream()).ReadToEnd();
int index = Regex.Match(responseee, "custf").Index;
responseee = responseee.Substring(index, 0x12);
responseee = responseee.Replace("\"", "").Replace(">", "").Trim();

this.response.Close();
lblErrormsg.Text = "connected";
Shillz
Newbie Poster
23 posts since Oct 2009
Reputation Points: 5
Solved Threads: 0
 

Are you getting an error message? If you are, what is the error?

stbuchok
Master Poster
730 posts since May 2011
Reputation Points: 120
Solved Threads: 93
 

yes. M getting error 407, proxy error on line no. 12, i.e.,
this.response = (HttpWebResponse)this.req.GetResponse();

Shillz
Newbie Poster
23 posts since Oct 2009
Reputation Points: 5
Solved Threads: 0
 

I added followin code in web.config

<defaultProxy>
<proxy bypassonlocal="True" usesystemdefault="False"  />  
</defaultProxy>


and changed cs code to as given below

this.req = (HttpWebRequest)WebRequest.Create("http://wwwd.way2sms.com/auth.cl");
this.req.CookieContainer = new CookieContainer();
                this.req.AllowAutoRedirect = false;
                this.req.Method = "POST";
                this.req.ContentType = "application/x-www-form-urlencoded";
                this.strNewValue = "username=" + ckuser + "&password=" + ckpass;
                this.req.ContentLength = this.strNewValue.Length;
                StreamWriter writer = new StreamWriter(this.req.GetRequestStream(), Encoding.ASCII);
                writer.Write(this.strNewValue);
                writer.Close();
 using (WebResponse res = req.GetResponse()) //error
                { 
                    response = (HttpWebResponse)res;
                    
                    Console.WriteLine(response.StatusCode); 
                }


                this.cookieCntr = this.req.CookieContainer;
                this.response.Close();
                this.req = (HttpWebRequest)WebRequest.Create("http://wwwd.way2sms.com//jsp/InstantSMS.jsp?val=0");
                this.req.CookieContainer = this.cookieCntr;
                this.req.Method = "GET";
                this.response = (HttpWebResponse)this.req.GetResponse();
                responseee = new StreamReader(this.response.GetResponseStream()).ReadToEnd();
                int index = Regex.Match(responseee, "custf").Index;
                responseee = responseee.Substring(index, 0x12);
                responseee = responseee.Replace("\"", "").Replace(">", "").Trim();
                this.response.Close();
                lblErrormsg.Text = "connected";
            }
            catch (Exception)
            {
                lblErrormsg.Text = "Error connecting to the server...";
            }

Web exception is caught saying 'The remote server returned an error: (404) Not Found.'

Shillz
Newbie Poster
23 posts since Oct 2009
Reputation Points: 5
Solved Threads: 0
 

FOR SIMPLY CONNECTING To ANOTHER SITE,

Use

Server.Tranfer("http://sdsd.jk");

OR

Response.Redirect("http://io.sdhd.jk",true);
Pri Bhowmik
Newbie Poster
17 posts since Jan 2012
Reputation Points: 8
Solved Threads: 4
 

I am connection to way2sms. I need to send message to amy number through this site, using my asp.net application.
response.redirect will redirect me to that site. I dont want that.

Shillz
Newbie Poster
23 posts since Oct 2009
Reputation Points: 5
Solved Threads: 0
 

Recheck the API

Pri Bhowmik
Newbie Poster
17 posts since Jan 2012
Reputation Points: 8
Solved Threads: 4
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: