HTTP POST

G

Guest

I need to send xml to a URL using HTTP POST and then read back in the response xml does anyone have a example of this
I have never done a project like this so please bear with me

here are the step

1. Create XML File (This part I can figure out, it's the next 2 steps I need help with.

2. Use VB.NET or ASP.NET to post the file or text to an URL address

HTTPS://someaddress/test.asp (xml goes here I guess?

3. Read the xml information that is posted bac

Thanks
Kent
 
C

Craig Vick [MSFT]

Hi Kent,

The simplest way would be something like the following:

Dim wc As New WebClient
With wc
.Credentials = New NetworkCredential("anonymous", "")
Dim response() As Byte =
.UploadFile("HTTPS://someaddress/test.asp", "POST", "XmlFile")
End With

The response is returned as a byte array. If you need more fine grained
control than this, you can use WebRequest.

Hope that helps,
Craig VB .NET Team
--------------------------------------------------------------------
This reply is provided AS IS, without warranty (express or implied).

--------------------
Thread-Topic: HTTP POST
thread-index: AcQQ+ogrvPCFKP0zSMa3VvwFEV1LOA==
X-Tomcat-NG: microsoft.public.dotnet.languages.vb
From: =?Utf-8?B?a2xrdWVuemVs?= <[email protected]>
Subject: HTTP POST
Date: Tue, 23 Mar 2004 09:16:08 -0800
Lines: 15
Message-ID: <[email protected]>
MIME-Version: 1.0
Content-Type: text/plain;
charset="Utf-8"
Content-Transfer-Encoding: 7bit
X-Newsreader: Microsoft CDO for Windows 2000
Content-Class: urn:content-classes:message
Importance: normal
Priority: normal
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.3790.0
Newsgroups: microsoft.public.dotnet.languages.vb
Path: cpmsftngxa06.phx.gbl
Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.languages.vb:190462
NNTP-Posting-Host: tk2msftcmty1.phx.gbl 10.40.1.180
X-Tomcat-NG: microsoft.public.dotnet.languages.vb

I need to send xml to a URL using HTTP POST and then read back in the
response xml does anyone have a example of this?
I have never done a project like this so please bear with me.

here are the steps

1. Create XML File (This part I can figure out, it's the next 2 steps I
need help with.)

2. Use VB.NET or ASP.NET to post the file or text to an URL address?

HTTPS://someaddress/test.asp (xml goes here I guess?)

3. Read the xml information that is posted back

Thanks,
Kent
 
G

Guest

Hi Craig

Could you please give me an example of posting an XML file to a .asp page using Webrequest. Here what I have so far. What is confusing me is would you post the xml file or a stream? I have an example from the place I am sending the XML to but their example uses MSXML 4.0 com object and I don't quit understand how to convert to use .NET object

Thanks again
Ken

Dim req as Webreques
dim rsp as webrespons

req = new Webrequest.Create(https://SomeURL.asp

req.method = "POST

<Do something here to send the XML

rsp = req.getresponse(
 
C

Craig Vick [MSFT]

Hi Kent,

You need to create a StreamWriter from the WebRequest and a StreamReader
from the XML file. Then in a loop you can read from the StreamReader and
write to the StreamWriter.

Here's some sample code to illustrate

Dim Reader As System.IO.BinaryReader
Dim Writer As System.IO.BinaryWriter
Dim LocalFileStream As System.IO.FileStream
Dim Buffer(FILE_BUFFER_SIZE - 1) As Byte

LocalFileStream = System.IO.File.OpenRead("c:\MyXml.xml")
Reader = New System.IO.BinaryReader(LocalFileStream)
Writer = req.GetRequestStream


Dim ReadCount As Integer = Reader.Read(Buffer, 0,
FILE_BUFFER_SIZE)

While ReadCount > 0

Writer.Write(Buffer, 0, ReadCount)
ReadCount = Reader.Read(Buffer, 0, FILE_BUFFER_SIZE)


End While

Hope this helps,
Craig VB.Net Team
--------------------------------------------------------------------
This reply is provided AS IS, without warranty (express or implied).

--------------------
Thread-Topic: HTTP POST
thread-index: AcQmR6UMKlltTho3QleZ6/dnWpMKyw==
X-WN-Post: microsoft.public.dotnet.languages.vb
From: "=?Utf-8?B?S2VudA==?=" <[email protected]>
References: <[email protected]>
<[email protected]>
Subject: RE: HTTP POST
Date: Mon, 19 Apr 2004 12:51:02 -0700
Lines: 19
Message-ID: <[email protected]>
MIME-Version: 1.0
Content-Type: text/plain;
charset="Utf-8"
Content-Transfer-Encoding: 7bit
X-Newsreader: Microsoft CDO for Windows 2000
Content-Class: urn:content-classes:message
Importance: normal
Priority: normal
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.3790.0
Newsgroups: microsoft.public.dotnet.languages.vb
Path: cpmsftngxa10.phx.gbl
Xref: cpmsftngxa10.phx.gbl microsoft.public.dotnet.languages.vb:196871
NNTP-Posting-Host: tk2msftcmty1.phx.gbl 10.40.1.180
X-Tomcat-NG: microsoft.public.dotnet.languages.vb

Hi Craig,

Could you please give me an example of posting an XML file to a .asp page
using Webrequest. Here what I have so far. What is confusing me is would
you post the xml file or a stream? I have an example from the place I am
sending the XML to but their example uses MSXML 4.0 com object and I don't
quit understand how to convert to use .NET object.

Thanks again,
Kent

Dim req as Webrequest
dim rsp as webresponse

req = new Webrequest.Create(https://SomeURL.asp)

req.method = "POST"

<Do something here to send the XML>

rsp = req.getresponse()
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top