locked
Question on VB.Net Post Parameter to HTTPS RRS feed

  • 問題

  • 你好
    我想問一下怎樣可以用 HttpWebRequest Class 去POST 一個 VARIABLE 到 一個 HTTPS 的WEBSITE?

    我需要做到的是 POST 一個 XML STRING 去另一個WEBSITE,
    這個WEBSITE 有一個XML Interface 可以READ 到這個POST 上來的 VARIABLE

    以下是我用HTML CODE 做的 TEST PAGE
    他可以成功地POST 到這個VARIABLOE 到這個WEB SITE 度

    <form action="https://XXX.XXX/INVOKE/SERVICE"  method="post">
    <TEXTAREA ROWS="7" COLS="89" NAME="request" id=request>
    
    
    </TEXTAREA>
    <input type="submit"/>
    </form>

    希望你們可以教教我怎樣可以用VB.NET 做到和這個HTML CODE 做的事 E.G. POST 這個 VARIABLE.

    I use the code below to make the HTTP request but not sure why it did not work
    Dim xmlString As String = "XML string"
            Dim strPostData As String = "request=" & xmlString
            Dim url As New Uri("https://XXX.XXX/INVOKE/SERVIC")
            Dim req As HttpWebRequest = HttpWebRequest.Create(url)
    
            req.Method = "POST"
            req.ContentType = "text/xml"
    
            Dim contentlength As Int32 = xmlString.Length
            ' req.ContentLength = contentlength
            Dim rsp As HttpWebResponse
    
    
    
            req.ContentLength = strPostData.Length
    
            Dim postwriter As New StreamWriter(req.GetRequestStream)
            postwriter.Write(strPostData) 有些人會轉個VARIABLE 做BYTE, 我試過但唔WORK... 不知道我有沒有轉錯
     postwriter.Close() rsp = req.GetResponse Dim r As New StreamReader(rsp.GetResponseStream) Dim responseText As String = r.ReadToEnd '<-- this do not return the correct response, it looks like the "request" variable is missing MsgBox(responseText)

    謝謝大家


    Chi
    2009年8月19日 上午 08:36

解答

所有回覆