Hit the external url

I have a form on my site. The user enters his email and selects a location from the drop-down list. Then I need to send this data to an external site by clicking on the URL with the user's location and email in the query bar.

I do it like this:

string url = "http://www.site.com/page.aspx?location=" + location.Text + "&email=" + email.Text;
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
HttpWebResponse response = (HttpWebResponse)request.GetResponse();

My client says that I do not click on their server, but, passing through the debugger, I get a response from my server. I also tried to keep track of what was going on with Firebug, and I noticed that there was no POST to this external site.

What am I doing wrong here?

+3
source share
4 answers

, POST, GET. , .

HttpWebRequest request = (HttpWebRequest)WebRequest.Create(URL);        
                request.KeepAlive = false;
                request.ProtocolVersion = HttpVersion.Version10;
                request.Method = "POST";
                request.Timeout = 30000;
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
+3
    string line;
    HttpWebRequest request = WebRequest.Create("http://www.yahoo.com") as HttpWebRequest;
    HttpWebResponse response = request.GetResponse() as HttpWebResponse;
    StreamReader streamr = new StreamReader(response.GetResponseStream());
    line = streamr.ReadToEnd();

,

+5

, Method WebRequest. , GET, POST.

:

HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
request.Method = "POST";
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
+2

, , , , (, site.com - , -:). , POST GET , , - :

string url = "http://www.site.com/page.aspx";
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);

// set request properties
request.Method = "POST";
request.ContentType = "application/x-www-form-urlencoded";

// set post values
string postValues = "location=" + location.Text + "&email=" + email.Text;
request.ContentLength = postValues.Length;

// write post values
StreamWriter streamWriter = new StreamWriter (request.GetRequestStream(), System.Text.Encoding.ASCII);
streamWriter.Write(postValues);
streamWriter.Close();

// process response
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
StreamReader streamReader = new StreamReader(response.GetResponseStream());
string responseData = streamReader.ReadToEnd();
streamReader.Close();

// do any processing needed on responseData...
+1

Source: https://habr.com/ru/post/1749091/


All Articles