Post数据打开URL不登陆页面c#asp.net
Post data to a open URL without landing on the page c# asp.net
我在一个网站上工作,该网站将数据发送到另一个网站,它有一个带有 URL 的登陆页面。问题是我不想做 REDirect 我只是想让它发送数据到那个页面并继续它下面的代码。
另一个站点没有 API 我该怎么做?
我一直在查看示例,所有示例都指的是 API url 的登录身份验证,但此 URL 不需要登录,只需发送即可URL(www.example.come/submit?Firstname=Firstname;LastName=LastName;) 的数据
类似的东西实际上没有将页面重定向到该站点。
您可以使用 WebRequest
// Create a request using a URL that can receive a post.
WebRequest request = WebRequest.Create ("http://www.contoso.com/PostAccepter.aspx ");
// Set the Method property of the request to POST.
request.Method = "POST";
// Create POST data and convert it to a byte array.
string postData = "This is a test that posts this string to a Web server.";
byte[] byteArray = Encoding.UTF8.GetBytes (postData);
// Set the ContentType property of the WebRequest.
request.ContentType = "application/x-www-form-urlencoded";
// Set the ContentLength property of the WebRequest.
request.ContentLength = byteArray.Length;
// Get the request stream.
Stream dataStream = request.GetRequestStream ();
// Write the data to the request stream.
dataStream.Write (byteArray, 0, byteArray.Length);
// Close the Stream object.
dataStream.Close ();
// Get the response.
WebResponse response = request.GetResponse ();
// Display the status.
Console.WriteLine (((HttpWebResponse)response).StatusDescription);
// Get the stream containing content returned by the server.
dataStream = response.GetResponseStream ();
// Open the stream using a StreamReader for easy access.
StreamReader reader = new StreamReader (dataStream);
// Read the content.
string responseFromServer = reader.ReadToEnd ();
// Display the content.
Console.WriteLine (responseFromServer);
// Clean up the streams.
reader.Close ();
dataStream.Close ();
response.Close ();
您可以阅读更多相关内容Here
我在一个网站上工作,该网站将数据发送到另一个网站,它有一个带有 URL 的登陆页面。问题是我不想做 REDirect 我只是想让它发送数据到那个页面并继续它下面的代码。
另一个站点没有 API 我该怎么做?
我一直在查看示例,所有示例都指的是 API url 的登录身份验证,但此 URL 不需要登录,只需发送即可URL(www.example.come/submit?Firstname=Firstname;LastName=LastName;) 的数据 类似的东西实际上没有将页面重定向到该站点。
您可以使用 WebRequest
// Create a request using a URL that can receive a post.
WebRequest request = WebRequest.Create ("http://www.contoso.com/PostAccepter.aspx ");
// Set the Method property of the request to POST.
request.Method = "POST";
// Create POST data and convert it to a byte array.
string postData = "This is a test that posts this string to a Web server.";
byte[] byteArray = Encoding.UTF8.GetBytes (postData);
// Set the ContentType property of the WebRequest.
request.ContentType = "application/x-www-form-urlencoded";
// Set the ContentLength property of the WebRequest.
request.ContentLength = byteArray.Length;
// Get the request stream.
Stream dataStream = request.GetRequestStream ();
// Write the data to the request stream.
dataStream.Write (byteArray, 0, byteArray.Length);
// Close the Stream object.
dataStream.Close ();
// Get the response.
WebResponse response = request.GetResponse ();
// Display the status.
Console.WriteLine (((HttpWebResponse)response).StatusDescription);
// Get the stream containing content returned by the server.
dataStream = response.GetResponseStream ();
// Open the stream using a StreamReader for easy access.
StreamReader reader = new StreamReader (dataStream);
// Read the content.
string responseFromServer = reader.ReadToEnd ();
// Display the content.
Console.WriteLine (responseFromServer);
// Clean up the streams.
reader.Close ();
dataStream.Close ();
response.Close ();
您可以阅读更多相关内容Here