Solved

how to send webrequest in ASP.NET to USPS

Posted on 2008-06-25
3
991 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
  • 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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

Suggested Solutions

ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

776 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