SivaKrishna Lavidi Ответов: 1

Как отправить HTTP-веб-запрос?


Привет я пытаюсь отправить HTTP post запрос пожалуйста найдите ниже :

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)


Что я уже пробовал:

Привет, я пытаюсь отправить запрос HTTP post, пожалуйста, найдите выше, что я описал проблему.

1 Ответов

Рейтинг:
7

Ravi Patidar 11721641

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();