Thanks Juntin.
But, i never wrote a line of code in ASP and, on your code, you dont send the authentication information to your server.
Do you have a easier example to me?
thanks!
Main Topics
Browse All TopicsHi all!
I need to develop an VB.NET app that will make a POST request to an WEB Server.
Actualy, i have an ASP Script as an example of how could i be this post to my web server. The ASP code is show below:
<%
' Server URL, HTTPS
const strTangramURL = "https://tangram/scripts/t
' Service Code
const strServiceId = "015"
' User and Password that will be used to authenticate on the WEB Server
const strTangramUser = "user"
const strTangramPwd = "password"
' *********** Mount a XML that will be sent to the server ***********
' recupera o destinatário da mensagem
strDestination = Request("destination")
' recupera o texto da mensagem
strText = Request("text")
' monta a string XML
strXML = _
"<xml version=""1.0"" encoding=""ISO-8859-1"">" & _
"<tangram_request service_id="" & strServiceId & "">" & _
" <send>" & _
" <destination>" & strDestination & "</destination>" & _
" <text>" & strText & "</text>" & _
" </send>" & _
"</tangram_request>"
' *********** envia ao TANGRAM ***********
' carrega a string XML par o componente
Set oDoc = CreateObject("MSXML2.DOMDo
oDoc.async = false
oDoc.loadXML strXML
' Here is where we connect to the server.....
Set oHttp = CreateObject("MSXML2.Serve
oHttp.SetTimeouts 10000, 10000, 10000, 10000
oHttp.open "POST", strTangramURL, False, strTangramUser, strTangramPwd
oHttp.send oDoc
strXML = oHttp.responseText
' *********** Verify the Result***********
' recupera o código de retorno da operação
oDoc.loadXML strXML
strCode = oDoc. selectSingleNode("/tangram
if strCode = "0" then
' redireciona para a página de sucesso
Response.Redirect "sucesso.asp"
else
' recupera a descrição do erro
strDescription = oDoc.selectSingleNode("/ta
' redireciona para a página de erro
Response.Redirect "erro.asp?msg=" & strDescription
end if
Set oDoc = Nothing
Set oHttp = Nothing
%>
So, can anybody shows me convert the ASP code above to a VB.NET method that will do the same thing?
Thanks all!
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
her is the easiest way:
Dim web As New System.Net.WebClient()
web.Headers.Add("Content-T
Dim d As Byte() = System.Text.Encoding.ASCII
Dim res As Byte() = web.UploadData("http://som
msgbox(System.Text.Encodin
Thank you so much for your kind help. Unfortunately, this didn't do quite what I was hoping. It appears to have scraped the page & the resulting images did not appear & links do not work. I was hoping the vb.net button would link to another site & append the query string using a post instead of get. The query string is based on user input. I've searched for days & haven't found a solution yet. Anyhow, nevertheless this solution will definitely come in handy for other things. Thanks again.
Business Accounts
Answer for Membership
by: Justin_WPosted on 2005-03-29 at 12:56:42ID: 13656443
Basically, you would need to do the following:
sponse" /> sponse.Sta tusCode" /> other than sCode.OK" />. nfinite _ t.Create(f ullUrl), System.Net.HttpWebRequest) ct = bAllowAutoRedirect icRedirect ions = 50
se(), System.Net.HttpWebResponse ) OK eam() m, responseEncoding) Redirect, System.Net.HttpStatusCode. MovedPerma nently rmat( _ NotFound rmat( _ rmat( _ eout) Then
1. create a HttpWebRequest object and use HttpWebRequest.Method = "POST".
2. set the Post data to contain whatever data you need the form to submit. This is similar to setting up a querystring for a GET Request, and you use Encoded name=value pairs.
3. "Post" (i.e. execute and get the response for) the HttpWebRequest.
Here is a sample Shared Function to get you started (It does GET requests, but you should be able to easily modify it to do POST requests).
Imports System.IO
'' <summary>
'' Programmatically performs an HTTP request for the <paramref name="fullUrl" /> URL's content.
'' </summary>
'' <exception cref="System.Exception">
'' Thrown if the HTTP Request fails, or if the <see cref="System.Net.HttpWebRe
'' has a <see cref="System.Net.HttpWebRe
'' <see cref="System.Net.HttpStatu
'' </exception>
'' <returns>The content from the requested URL's HTTP Response.</returns>
Public Shared Function ExecuteUrl( _
ByVal fullUrl As String, _
Optional ByVal bAllowAutoRedirect As Boolean = True, _
Optional ByVal iTimeout As Integer = System.Threading.Timeout.I
) As String
Dim webRequest As System.Net.HttpWebRequest
Dim webResponse As System.Net.HttpWebResponse
Try
'Create an HttpWebRequest with the specified URL.
webRequest = CType(System.Net.WebReques
webRequest.AllowAutoRedire
'webRequest.MaximumAutomat
webRequest.Timeout = iTimeout
'Send the request and wait for a response.
Try
webResponse = CType(webRequest.GetRespon
Select Case (webResponse.StatusCode)
Case System.Net.HttpStatusCode.
'read the content from the response
Dim responseStream As System.IO.Stream = _
webResponse.GetResponseStr
Dim responseEncoding As System.Text.Encoding = _
System.Text.Encoding.UTF8
' Pipes the response stream to a higher level stream reader with the required encoding format.
Dim responseReader As New StreamReader(responseStrea
Dim responseContent As String = _
responseReader.ReadToEnd()
Return responseContent
Case System.Net.HttpStatusCode.
Throw New System.Exception(String.Fo
"Unable to read response content. URL has moved. StatusCode={0}.", _
webResponse.StatusCode))
Case System.Net.HttpStatusCode.
Throw New System.Exception(String.Fo
"Unable to read response content. URL not found. StatusCode={0}.", _
webResponse.StatusCode))
Case Else
Throw New System.Exception(String.Fo
"Unable to read response content. StatusCode={0}.", _
webResponse.StatusCode))
End Select
Catch we As System.Net.WebException
'If (we.Status = Net.WebExceptionStatus.Tim
' Return False
'End If
Throw New System.Exception( _
"Unable to execute URL.", _
we)
Finally
If (Not IsNothing(webResponse)) Then
webResponse.Close()
End If
End Try
Catch e As System.Exception
Throw New System.Exception( _
"Unable to execute URL.", _
e)
End Try
End Function