0

注意:这个问题已被编辑过最初提出的问题

我正在开发一个 Windows 服务,该服务每天查询 Web 服务的数据,将其与当前存在的数据进行比较,然后将其发布到客户端的网页。

远程帖子的代码执行良好,但客户端的网页上永远不会发生更新......

Imports Microsoft.VisualBasic
Imports System.Collections.Specialized

Public Class RemotePost

    Public Property Inputs As New NameValueCollection()
    Public Property URL As String
    Public Property Method As String = "post"
    Public Property FormName As String = "_xclick"

    Public Sub Add(ByVal name As String, ByVal value As String)
        _Inputs.Add(name, value)
    End Sub

    Public Sub Post()
        Dim client as New WebClient()
        client.Headers.Add("Content-Type", "application/x-www-form-urlencoded")
        Dim responseArray = client.UploadValues(URL, Method, Inputs)
    End Sub
End Class

我认为原因是上述代码生成的帖子与表单本身手动发布的帖子不同。

这是由上述代码生成的帖子的示例:

POST http://www.thisdomain.com/add-event/ HTTP/1.1
Content-Type: application/x-www-form-urlencoded
Host: thisdomain.com
Content-Length: 116
Expect: 100-continue
Connection: Keep-Alive

no_location=0&event_name=Cycle-Fix+MTB+Tour+-+3+Days+ABC&event_start_date=2013%2f04%2f06&location_state=Eastern+Cape

这是在页面本身上生成的帖子的示例:

POST http://www.thisdomain.com/add-event/ HTTP/1.1
Host: thisdomain.com
Connection: keep-alive
Content-Length: 2844
Cache-Control: max-age=0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Origin: http://thisdomain.com
User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.31 (KHTML, like Gecko) Chrome/26.0.1410.64 Safari/537.31
Content-Type: multipart/form-data; boundary=----WebKitFormBoundary8u14QB8zBLGQeIwu
Referer: http://thisdomain.com/add-event/
Accept-Encoding: gzip,deflate,sdch
Accept-Language: en-US,en;q=0.8
Accept-Charset: UTF-8,*;q=0.5
Cookie: wp-settings-1=m5%3Do%26editor%3Dtinymce%26libraryContent%3Dbrowse%26align%3Dleft%26urlbutton%3Dnone%26imgsize%3Dfull%26hidetb%3D1%26widgets_access%3Doff; wp-settings-time-1=1367827995; wordpress_test_cookie=WP+Cookie+check; wordpress_logged_in_8d8e9e110894b9cf877af3233b3a007b=admin%7C1368089227%7C69a33748ee5bbf638a315143aba81313; devicePixelRatio=1

------WebKitFormBoundary8u14QB8zBLGQeIwu
Content-Disposition: form-data; name="event_name"

test event
------WebKitFormBoundary8u14QB8zBLGQeIwu
Content-Disposition: form-data; name="event_start_date"

2013-05-07
------WebKitFormBoundary8u14QB8zBLGQeIwu
Content-Disposition: form-data; name="event_start_time"

01:00 AM
------WebKitFormBoundary8u14QB8zBLGQeIwu
Content-Disposition: form-data; name="event_end_time"

02:15 AM
------WebKitFormBoundary8u14QB8zBLGQeIwu
Content-Disposition: form-data; name="recurrence_freq"

daily
------WebKitFormBoundary8u14QB8zBLGQeIwu
Content-Disposition: form-data; name="recurrence_interval"


------WebKitFormBoundary8u14QB8zBLGQeIwu
Content-Disposition: form-data; name="recurrence_byweekno"

1
------WebKitFormBoundary8u14QB8zBLGQeIwu
Content-Disposition: form-data; name="recurrence_byday"

0
------WebKitFormBoundary8u14QB8zBLGQeIwu
Content-Disposition: form-data; name="recurrence_days"

0
------WebKitFormBoundary8u14QB8zBLGQeIwu
Content-Disposition: form-data; name="location_latitude"

38.0333333
------WebKitFormBoundary8u14QB8zBLGQeIwu
Content-Disposition: form-data; name="location_longitude"

-117.23333330000003    

------WebKitFormBoundary8u14QB8zBLGQeIwu
Content-Disposition: form-data; name="location_name"

test
------WebKitFormBoundary8u14QB8zBLGQeIwu
Content-Disposition: form-data; name="location_address"

test
------WebKitFormBoundary8u14QB8zBLGQeIwu
Content-Disposition: form-data; name="location_town"

test
------WebKitFormBoundary8u14QB8zBLGQeIwu
Content-Disposition: form-data; name="location_state"

Georgia

显然,表单的帖子比我的帖子要多得多。不幸的是,我恐怕我不明白这一切。

我对这些差异有以下担忧:

  • 我的(显然)查询字符串数据没有被读取,因为它没有被正确发送($_GET 而不是 $_POST)
  • PHP中可能存在验证代码,该代码在此帖子之后保存数据,将其阻塞在某处

谁能解释这里到底有什么区别以及如何根据我的要求模拟表单的帖子?

4

1 回答 1

1

你这样做的方式只是打印html。它不张贴。

看看这个问题。

在 vb.net 中发布到网页(win forms、桌面,而不是 ASP.net)

通过使用 WebClient 类,您可以将所需的信息发送到网站。发布数据将采用以下形式:

For i As Integer = 0 To Inputs.Keys.Count - 1
    if postData <> "" Then postData &= "&"

    postData &= Inputs.Keys(i) & "=" & Inputs(Inputs.Keys(i))
Next
于 2013-05-06T13:28:02.000 回答