How to run a URL behind the scenes without displaying it in a browser?

I want to basically run the URL that I would create behind the scenes without displaying it in the browser to the user ... I think I could use HTTPWebRequest or maybe something similar to curl? ... but do I need to really just basically start / run the generated url? How can i do this?

+3
source share
4 answers

Use the WebRequest class and its friends.

Other more modern options are the WebClient class, which may be easier to use in some cases, and the HttpClient class , which gives you very detailed control over requests and responses.

+6
source

one way i used: post to hidden iframe

+1
source

http://www.netomatix.com/httppostdata.aspx

, URL-:

private void OnPostInfoClick(object sender, System.EventArgs e)
{
    string strId = UserId_TextBox.Text;
    string strName = Name_TextBox.Text;

    ASCIIEncoding encoding=new ASCIIEncoding();
    string postData="userid="+strId;
    postData += ("&username="+strName);
    byte[]  data = encoding.GetBytes(postData);

    // Prepare web request...
    HttpWebRequest myRequest = (HttpWebRequest)WebRequest.Create("http://localhost/MyIdentity/Default.aspx");
    myRequest.Method = "POST";
    myRequest.ContentType="application/x-www-form-urlencoded";
    myRequest.ContentLength = data.Length;
    Stream newStream=myRequest.GetRequestStream();

    // Send the data.
    newStream.Write(data,0,data.Length);
    newStream.Close();
}
+1

, - ?

Dim request = WebRequest.Create(strUrl)
request.Method = "POST"
request.ContentType = "text/xml" 'change to whatever you need

, , -, ,

Using sw As New StreamWriter(request.GetRequestStream())
    sw.WriteLine(HtmlOrXml)
End Using

:

Dim response = CType(request.GetResponse(), HttpWebResponse)

StreamReader . , MSDN.

+1

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


All Articles