如何发送HTTP Web请求? [英] How do send HTTP web request?

查看:211
本文介绍了如何发送HTTP Web请求?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好我正在尝试发送HTTP帖子请求,请在下面找到:



 http://test.p-44 .com / xml / pickup.xml?p44Login = DEMO& p44Password = DEMO& xml =< dispatchrequest>< vendorcode> CODE < /   vendorcode  >  ...( 发​​送请求xml) ... < /   dispatchrequest  >  

我正在尝试 每次我得到上述请求时网页例外你可以帮助 这个。

示例代码:

Dim WebRequest As HttpWebRequest = CType (HttpWebRequest.Create( https:/ /test.p-44.com/xml/pickup.xml),HttpWebRequest)

WebRequest.AllowAutoRedirect = False
WebRequest.Method = POST;
WebRequest.ContentType = text / xml
Dim requestStream As Stream = WebRequest.GetRequestStream()
Dim Somebyte() As Byte = Encoding.UTF8.GetBytes(requstXML)
requestStream。写(Somebyte, 0 ,Somebyte.Length)
requestStream.Close()

Dim myResponseFDX As HttpWebResponse = CType (WebRequest.GetResponse(),HttpWebResponse)





我尝试过:



你好我正在尝试发送HTTP帖子请求,请在上面找到我描述的问题。

解决方案

使用 System.Net;
使用 System.Text; // 类编码
POST

var request =(HttpWebRequest)WebRequest.Create( http:// www .example.com的/ recepticle.aspx);

var postData = thing1 =你好;
postData + = & thing2 = world;
var data = Encoding.ASCII.GetBytes(postData);

request.Method = POST;
request.ContentType = application / x-www-form-urlencoded;
request.ContentLength = data.Length;

使用 var stream = request.GetRequestStream())
{
stream.Write(data, 0 ,data.Length);
}

var response =(HttpWebResponse)request.GetResponse();

var responseString = new StreamReader(response.GetResponseStream())。ReadToEnd ();
GET

var request =(HttpWebRequest)WebRequest.Create( http://www.example.com/recepticle.aspx);

var response =(HttpWebResponse)request.GetResponse();

var responseString = new StreamReader(response.GetResponseStream())。ReadToEnd ();


Hi i am trying to send the HTTP post request please find below :

http://test.p-44.com/xml/pickup.xml?p44Login=DEMO&p44Password=DEMO&xml=<dispatchrequest><vendorcode>CODE</vendorcode> ... (rest of dispatch request xml) ... </dispatchrequest>

when i am trying to process the above request every time i got web exception will you please help me on this.

sample code :

Dim WebRequest As HttpWebRequest = CType(HttpWebRequest.Create("https://test.p-44.com/xml/pickup.xml"), HttpWebRequest)
          
          WebRequest.AllowAutoRedirect = False
          WebRequest.Method = "POST";
          WebRequest.ContentType = "text/xml"
         Dim requestStream As Stream = WebRequest.GetRequestStream()
         Dim Somebyte() As Byte = Encoding.UTF8.GetBytes(requstXML)
         requestStream.Write(Somebyte, 0, Somebyte.Length)
         requestStream.Close()

         Dim myResponseFDX As HttpWebResponse = CType(WebRequest.GetResponse(), HttpWebResponse)



What I have tried:

Hi i am trying to send the HTTP post request please find above i've describe the problem.

解决方案

using System.Net;
using System.Text;  // for class Encoding
POST

var request = (HttpWebRequest)WebRequest.Create("http://www.example.com/recepticle.aspx");

var postData = "thing1=hello";
    postData += "&thing2=world";
var data = Encoding.ASCII.GetBytes(postData);

request.Method = "POST";
request.ContentType = "application/x-www-form-urlencoded";
request.ContentLength = data.Length;

using (var stream = request.GetRequestStream())
{
    stream.Write(data, 0, data.Length);
}

var response = (HttpWebResponse)request.GetResponse();

var responseString = new StreamReader(response.GetResponseStream()).ReadToEnd();
GET

var request = (HttpWebRequest)WebRequest.Create("http://www.example.com/recepticle.aspx");

var response = (HttpWebResponse)request.GetResponse();

var responseString = new StreamReader(response.GetResponseStream()).ReadToEnd();


这篇关于如何发送HTTP Web请求?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆