討論區快速選單
知識庫快速選單
政府補助!學嵌入式+物聯網 網路投保旅行平安險 最完整AWS雲端解決方案培訓
[ 回上頁 ] [ 討論區發言規則 ]
vb2008 HttpWebRequest "post"問題
更改我的閱讀文章字型大小
作者 : andyc2002(阿天)
[ 貼文 4 | 人氣 0 | 評價 0 | 評價/貼文 0 | 送出評價 0 次 ] 
[ 給個讚 ]  [ 給個讚 ]  [ 回應本文 ]  [ 發表新文 ]  [ 回上頁 ] [ 回討論區列表 ] [ 回知識入口 ]
2012/2/15 下午 11:46:56
各位好
我是想去下方的link
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
然後用"post"把數量改為2
但不知為何server總是return 503error...
請問有人可以幫幫我嗎...

code:

Dim logincookie As CookieContainer
     Dim response As HttpWebResponse
     Dim tempCookies As New Cookie
     Dim req As HttpWebRequest
     Dim postdata As String
     Dim encoding As New UTF8Encoding
     Dim byteData As Byte()
     Dim quant1 As String
     Dim quant2 As String
     Dim quantint As Integer
     Dim totalquan As Integer
     Dim cartid As String
     Dim quant3 As String
     Dim htmltext As String
     Dim cartid2 As String
     Dim reqreader As StreamReader
     Dim postreqstream As Stream


     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
作者 : andyc2002(阿天)
[ 貼文 4 | 人氣 0 | 評價 0 | 評價/貼文 0 | 送出評價 0 次 ] 
[ 給個讚 ]  [ 給個讚 ]  [ 回應本文 ]  [ 發表新文 ]  [ 回上頁 ] [ 回討論區列表 ] [ 回知識入口 ]
2012/2/15 下午 11:48:24
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()


     'use "POST" to change the quantity to 2
     req = DirectCast(WebRequest.Create("http://store.apple.com/hk-zh/hybrid_cartx"), HttpWebRequest)
     req.Method = "POST"
     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"
     req.Headers("Accept-Charset") = "UTF-8,*"
     req.KeepAlive = True
     req.Headers("X-Requested-With") = "XMLHttpRequest"
     req.ContentType = "application/x-www-form-urlencoded; charset=UTF-8"
     req.Referer = "http://store.apple.com/hk-zh/cart"
     req.CookieContainer = logincookie
     req.Headers("Pragma") = "no-cache"
     req.Headers("Cache-Control") = "no-cache"

'construct POST data and write to stream
     quant1 = "maxlength=\""3\"" id=\"""
     quant2 = "quantity\"" /> <\/li> <li class=\"
     quantint = InStr(htmltext, quant1) + quant1.Length - 1
     cartid = htmltext.Substring(quantint, InStr(htmltext, quant2) - 1 - quantint)
     totalquan = CInt(TextBox1.Text)
作者 : andyc2002(阿天)
[ 貼文 4 | 人氣 0 | 評價 0 | 評價/貼文 0 | 送出評價 0 次 ] 
[ 給個讚 ]  [ 給個讚 ]  [ 回應本文 ]  [ 發表新文 ]  [ 回上頁 ] [ 回討論區列表 ] [ 回知識入口 ]
2012/2/15 下午 11:48:51
postdata = cartid & "quantity=" & totalquan.ToString
     postdata += "&" & cartid & "packageText=&" & cartid & "messageText=&"
     quant3 = "_a=up&cartid="
     cartid2 = htmltext.Substring(InStr(htmltext, quant3) - 1, 100)
     postdata += cartid2.Substring(0, InStr(cartid2, Chr(34)) - 1)
     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()

     WebBrowser1.DocumentText = htmltext

     Catch ex As Exception
     MsgBox(ex.ToString & vbCrLf & ex.Message.ToString)
     End Try
作者 : andyc2002(阿天)
[ 貼文 4 | 人氣 0 | 評價 0 | 評價/貼文 0 | 送出評價 0 次 ] 
[ 給個讚 ]  [ 給個讚 ]  [ 回應本文 ]  [ 發表新文 ]  [ 回上頁 ] [ 回討論區列表 ] [ 回知識入口 ]
2012/2/18 下午 08:42:42
有人可以幫我嗎><
 板主 : 徵求中
 > Microsoft Visual Studio 2008 - 討論區
 - 最近熱門問答精華集
 - 全部歷史問答精華集
 - Microsoft Visual Studio 2008 - 知識庫
  ■ 全站最新Post列表
  ■ 我的文章收藏
  ■ 我最愛的作者
  ■ 全站文章收藏排行榜
  ■ 全站最愛作者排行榜
  ■  月熱門主題
  ■  季熱門主題
  ■  熱門主題Top 20
  ■  本區Post排行榜
  ■  本區評價排行榜
  ■  全站專家名人榜
  ■  全站Post排行榜
  ■  全站評價排行榜
  ■  全站人氣排行榜
 請輸入關鍵字 
  開始搜尋
 
Top 10
評價排行
Microsoft Visual Studio 2008
1 joe 270 
2 Raymond 90 
3 marlon 70 
4 丹尼爾 50 
5 好說 50 
6 smfy 50 
7 小誠 20 
8 愛睏魚 20 
9 水瓶天賞 20 
10 ozzy 10 
Microsoft Visual Studio 2008
  專家等級 評價  
  一代宗師 10000  
  曠世奇才 5000  
  頂尖高手 3000  
  卓越專家 1500  
  優秀好手 750  
Microsoft Internet Explorer 6.0. Screen 1024x768 pixel. High Color (16 bit).
2000-2018 程式設計俱樂部 http://www.programmer-club.com.tw/
0.03125