vb2008 HttpWebRequest "post"

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • andyc2002
    New Member
    • Feb 2012
    • 1

    vb2008 HttpWebRequest "post"

    Hi all, I have problem on use HttpWebRequest with "POST" method.
    First, I access
    http://store.apple.com/hk-zh/configu...=UNLO CKED%2FWW
    this link and go to the cart page.
    Then when I change the quantity to 2, I had see the live http header to use "POST" and submit the content to the server.
    I follow the header and write with vb2008, but I get the server return 503 error on the code that getting response, would you mind to tell me that I got problem on where?

    Code:
    logincookie = New CookieContainer()
         Try
         'access item page
         req = DirectCast(WebRequest.Create("http://store.apple.com/hk-zh/configure/MD198ZP/A?option.iphone_applecare=none&option.iphone_bumpers=none&option.iphone_4_dock=none&option.additional_apple_usb_power_adaptor=none&option.additional_apple_dock_connector_to_usb_cable=none&add-to-cart=add-to-cart&cppart=UNLOCKED%2FWW"), HttpWebRequest)
         req.Method = "GET"
         req.UserAgent = "Mozilla/5.0 (Windows NT 5.1; rv:9.0.1) Gecko/20100101 Firefox/9.0.1"
         req.Accept = "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8"
         req.Headers("Accept-Language") = "zh-tw,en-us;q=0.7,en;q=0.3"
         'req.Headers("Accept-Encoding") = "gzip, deflate"
         req.Headers("Accept-Charset") = "UTF-8,*"
         req.KeepAlive = True
         req.CookieContainer = logincookie
    
    response = DirectCast(req.GetResponse(), HttpWebResponse)
         For Each tempCookies In response.Cookies
         logincookie.Add(tempCookies)
         Next
    
         reqreader = New StreamReader(response.GetResponseStream())
         htmltext = reqreader.ReadToEnd
         reqreader.Close()
         response.Close()
    than post data(i sure that the post content are correct)

    Code:
     byteData = encoding.GetBytes(postdata)
         req.ContentLength = byteData.Length
         postreqstream = req.GetRequestStream()
         postreqstream.Write(byteData, 0, byteData.Length)
         postreqstream.Close()
    
    'server return 503 in this code
         response = DirectCast(req.GetResponse(), HttpWebResponse)
    
         reqreader = New StreamReader(response.GetResponseStream())
         htmltext = reqreader.ReadToEnd
         reqreader.Close()
         response.Close()
    i have error on "response = DirectCast(req. GetResponse(), HttpWebResponse )"

    For programmers: provide error codes, snippets of code related to error code(no longer than 20 lines)
    sorry i may be more than 20 lines a little bit...
Working...