gpt4 book ai didi

http-post - 以编程方式提交到 .do 文件

转载 作者:行者123 更新时间:2023-12-02 23:10:40 24 4
gpt4 key购买 nike

我希望有人能知道这个问题的答案。我正在编写一个应用程序,它必须向安全网页提交请求,这本身就是安全网页表单页面的操作(不是为了说明显而易见的事情,但基本上我正在尝试提交将要填写的信息在初始表单上,并将其提交到表单“操作”中指定的页面)。我必须提交的“action”URL 以“.do”扩展名结尾,据我所知,它指定了一个用 JAVA 动态构建的页面。

我的问题是,当我提交时我没有得到任何返回。这是我正在使用的代码(VB.Net,目标版本 4.0):

Dim PostValues As New NameValueCollection()
Dim RespString As String
Dim RespBytes() As Byte

' URL below is "action" for web form at https://www.deadiversion.usdoj.gov/webforms/validateLogin.jsp
Dim URL As String = "https://www.deadiversion.usdoj.gov/webforms/validateLogin.do"
' These POST values are obtained by examing the source code for the web form ".jsp" page, looking for "input" tags
PostValues.Add("submit", "")
PostValues.Add("deaNum", "--dea number value for our company--")
PostValues.Add("lname", HttpUtility.UrlEncode("boca pharmacal inc"))
PostValues.Add("ssn", "")
PostValues.Add("taxid", "--tax id value for our company--")
PostValues.Add("buttons.next", "Login")

Dim client As New WebClient()
client.Headers.Add("Content-Type", "application/x-www-form-urlencoded")
client.UseDefaultCredentials = True
RespBytes = client.UploadValues(URL, "POST", PostValues)
RespString = Encoding.UTF8.GetString(RespBytes)

当我运行此代码时,RespBytes 的长度为 0,然后 RespString 只是一个空字符串。相比之下,如果我实验性地替换上面评论中提到的以“.jsp”结尾的 URL,我会收到响应,没有问题,所以我认为它与它是“https”这一事实没有任何关系“网址。

我还实验性地获取了“.do”URL,将其粘贴到我的浏览器中,然后尝试直接通过网络浏览到它。在这种情况下,它会发回一个空页面,就像我以编程方式尝试时它没有发回任何内容一样,这似乎表明由于某种原因它看不到我尝试通过 POST 发送的值。

这与 URL 以“.do”结尾有关吗?提交到这样的 URL 是否需要我在提交时做一些特殊的事情?

最佳答案

这是直接来自 Microsoft 网站的代码片段:

Imports System
Imports System.IO
Imports System.Net
Imports System.Text
Namespace Examples.System.Net
Public Class WebRequestPostExample

Public Shared Sub Main()
' Create a request using a URL that can receive a post.
Dim request As WebRequest = WebRequest.Create("http://www.contoso.com/PostAccepter.aspx ")
' Set the Method property of the request to POST.
request.Method = "POST"
' Create POST data and convert it to a byte array.
Dim postData As String = "This is a test that posts this string to a Web server."
Dim byteArray As Byte() = Encoding.UTF8.GetBytes(postData)
' Set the ContentType property of the WebRequest.
request.ContentType = "application/x-www-form-urlencoded"
' Set the ContentLength property of the WebRequest.
request.ContentLength = byteArray.Length
' Get the request stream.
Dim dataStream As Stream = request.GetRequestStream()
' Write the data to the request stream.
dataStream.Write(byteArray, 0, byteArray.Length)
' Close the Stream object.
dataStream.Close()
' Get the response.
Dim response As WebResponse = request.GetResponse()
' Display the status.
Console.WriteLine(CType(response, HttpWebResponse).StatusDescription)
' Get the stream containing content returned by the server.
dataStream = response.GetResponseStream()
' Open the stream using a StreamReader for easy access.
Dim reader As New StreamReader(dataStream)
' Read the content.
Dim responseFromServer As String = reader.ReadToEnd()
' Display the content.
Console.WriteLine(responseFromServer)
' Clean up the streams.
reader.Close()
dataStream.Close()
response.Close()
End Sub
End Class
End Namespace

您可以在 http://msdn.microsoft.com/en-us/library/debx8sh9.aspx?cs-save-lang=1&cs-lang=vb#code-snippet-27 找到代码

关于http-post - 以编程方式提交到 .do 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13960584/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com