Solved

how to send webrequest in ASP.NET to USPS

Posted on 2008-06-25
3
1,001 Views
Last Modified: 2013-11-26
I need to send request to receive response from USPS server.

I was doing in in ASP with the code given below but now i wants to send same USPS url using ASP.net (VB.net).Please provide me the sample code or reference .I am new in ASP.net and don't know how to send request to receive reply.


set xmlhttp = server.Createobject(MSXMLprogID)
      if err.number <> 0 then
            USPSrates = "USPS : " & err.Description
            exit function
      end if
      on error goto 0

      'Test server
      'xmlhttp.Open "POST","http://testing.shippingapis.com/ShippingAPITest.dll",false
      
      xmlhttp.Open "POST","http://production.shippingapis.com/ShippingAPI.dll",false
      xmlhttp.setRequestHeader "Content-Type","application/x-www-form-urlencoded"
      xmlhttp.send "API=" & API & "&XML=" & strXMLSend
      if xmlhttp.status <> 200 then
            USPSrates = "USPS : HTTP Error " & xmlhttp.status & " - " & xmlhttp.statusText & "."
            Set xmlhttp = nothing
            exit function
      end if
      strXMLRec = xmlhttp.responseText
      Set xmlhttp = nothing

      'Process return
      set xmlDom = Server.CreateObject(XMLDOMprogID)
      xmlDom.async = "false"
      xmlDom.LoadXML (strXMLRec)

Regards,
0
Comment
Question by:sdugar
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 18

Accepted Solution

by:
jcoehoorn earned 500 total points
ID: 21865256
Don't use CreateObject in .Net.  Ever.
On Error style error handling isn't a good idea either.
The 'Set' keyword has a completely different meaning in VB.Net than it did in VB6/VBScript.

To send your web request, use System.Net.WebClient or System.Net.HttpWebRequest/System.Net.HttpWebRepsonse.

http://jcoehoorn.vox.com/library/post/dos-and-donts-for-vb6-programmers-using-net.html

0
 

Author Comment

by:sdugar
ID: 21865484
Dear jcoehoorn

Thanks for your reply.But i aman ASP programer and wants to know how to recreate the above ASP code in ASP.Net

i wants to know how to send request in ASP.net.Can you provide me sample code for this.

 'xmlhttp.Open "POST","http://testing.shippingapis.com/ShippingAPITest.dll",false
     
      xmlhttp.Open "POST","http://production.shippingapis.com/ShippingAPI.dll",false
      xmlhttp.setRequestHeader "Content-Type","application/x-www-form-urlencoded"
      xmlhttp.send "API=" & API & "&XML=" & strXMLSend


regards,
Sunny
0
 
LVL 18

Assisted Solution

by:jcoehoorn
jcoehoorn earned 500 total points
ID: 21865822
Remember, ASP.Net is not ASP.  What worked in ASP isn't necessarily a good idea in ASP.Net.  The pointers I gave you in the first post are all valid, and should be followed- don't ever use CreateObject for anything.  Don't use On Error.  Don't use the Set keyword.  If you want to write ASP.Net code, you need to understand how ASP.Net expects things to be done.
Dim wc As New System.Net.WebClient()
wc.Headers.Add(Net.HttpRequestHeader.ContentType, "application/x-www-form-urlencoded")
wc.QueryString.Add("API", API)
wc.QueryString.Add("XML", strXMLSend)
 
wc.DownloadString("http://production.shippingapis.com/ShippingAPI.dll")

Open in new window

0

Featured Post

Ready to get started with anonymous questions?

It's easy! Check out this step-by-step guide for asking an anonymous question on Experts Exchange.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

632 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question