gpt4 book ai didi

银光 HTTP POST

转载 作者:行者123 更新时间:2023-12-02 06:12:06 26 4
gpt4 key购买 nike

我只是想在 http://www.test.com/test.asp?test1=3 上执行一个 http post .这是我一直在尝试使用的代码:

    private void pif_test_conn()
{


Uri url = new Uri("http://www.test.com/test.asp?test1=3", UriKind.Absolute);



if (httpResult == true)
{


HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(url);
request.ContentType = "application/x-www-form-urlencoded";
request.Method = "POST";
request.BeginGetResponse(new AsyncCallback(ReadCallback), request);

}



return ;
}


private void ReadCallback(IAsyncResult asynchronousResult)
{


HttpWebRequest request = (HttpWebRequest)asynchronousResult.AsyncState;


HttpWebResponse response = (HttpWebResponse)request.EndGetResponse(asynchronousResult);

using (StreamReader streamReader1 = new StreamReader(response.GetResponseStream()))
{

string resultString = streamReader1.ReadToEnd();

MessageBox.Show("Using HttpWebRequest: " + resultString, "Found", MessageBoxButton.OK);
}

}

当我执行这段代码时,我的程序触发了 Application_UnhandledException 事件。不确定我做错了什么。

最佳答案

您是否尝试发布到其他主机?该行为可能导致 XSS 安全问题,因此不可用。


string responseValue = "";
AutoResetEvent syncRequest = new AutoResetEvent(false);
Uri address = new Uri(HtmlPage.Document.DocumentUri, "/sample.aspx");

WebRequest request = WebRequest.Create(address);
request.Method = "POST";
request.BeginGetRequestStream(getRequestResult =>
{
// Send packet data
using (Stream post = request.EndGetRequestStream(getRequestResult))
{
post.Write(buffer, 0, buffer.Length);
post.Close();
}

// wait for server response
request.BeginGetResponse(getResponseResult =>
{
WebResponse response = request.EndGetResponse(getResponseResult);
responseValue=new StreamReader(response.GetResponseStream()).ReadToEnd();

syncRequest.Set();

}, null);

}, null);

syncRequest.WaitOne();

MessageBox.Show(
"Using WebRequest: " + responseValue,
"Found", MessageBoxButton.OK);

HTH

关于银光 HTTP POST,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1528872/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com