dqy1265 2013-05-06 13:14
浏览 78

从Windows服务远程发布到网页

NOTE: This question has been edited what was originally asked

I'm developing a windows service that, daily, queries a web service for data, compares that to currently existing data and then posts it to the client's webpage.

The code for the remote post executes fine, but updates never happen on the client's web page...

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

I believe the reason for this is that the post generated by the above code is different to what the form itself posts manually.

Here's an example of a post generated by the above code:

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

And here's an example of a post generated on the page itself:

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

Clearly there's a lot more happening with the form's post than is the case with mine. Unfortunately, I'm afraid I don't understand all of it.

I have the following concerns about these differences:

  • That my (apparently) querystring data is not being read because it's not being sent correctly ($_GET as opposed to $_POST)
  • That there is possibly validation code in the PHP that saves the data after this post that is blocking it somewhere

Can anyone explain what exactly the differences here are and how I can emulate the form's post as per my requirement?

  • 写回答

1条回答 默认 最新

  • dqkf49487 2013-05-06 13:28
    关注

    The way you did it just print html. It does not post.

    Check out this question.

    POST to webpage in vb.net (win forms, desktop, not ASP.net)

    By using the WebClient class, you can send the information you want to a website. The post data will be in the form of:

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

报告相同问题?

悬赏问题

  • ¥15 fluent的在模拟压强时使用希望得到一些建议
  • ¥15 STM32驱动继电器
  • ¥15 Windows server update services
  • ¥15 关于#c语言#的问题:我现在在做一个墨水屏设计,2.9英寸的小屏怎么换4.2英寸大屏
  • ¥15 模糊pid与pid仿真结果几乎一样
  • ¥15 java的GUI的运用
  • ¥15 Web.config连不上数据库
  • ¥15 我想付费需要AKM公司DSP开发资料及相关开发。
  • ¥15 怎么配置广告联盟瀑布流
  • ¥15 Rstudio 保存代码闪退