2015-04-19 151 views
1

我目前正在通過爲網站申請編程技巧。現在我可以通過應用程序登錄到網頁。我現在的重點是讓用戶通過應用程序更改他/她的個人資料並將其保存到網站。問題是沒有任何事情發生在網站上,我沒有得到任何錯誤代碼或任何東西。JSOUP向表單提交POST

當我點擊保存按鈕保存最近的網站,我得到了下面的頭信息上進行更改(使用谷歌瀏覽器F12 - >網絡):

firstname: John 
lastname:Random 
streetAddress:Woodstreet 12 
careOfAddress: 
zipCode:417 22 
city:Woods 
country:US 
phone:111122000 
languageForeignKey:4FCB3B38F96800010003004E 
invoiceDeliveryMethod:email 
preferredMessageMethod:sms 
save_button: 
utf8:✓ 
authenticity_token:+RadnomKey40134128Notes= 

我的方法

public void setUpdatedContactInformation(String cookie, String firstName, 
     String lastName, String streeAdress, String coAdress, 
     String zipCode, String city, String country, 
     String alternativPhone, String language, String deliveryMethod, 
     String messageMethod, String token) { 
    try { 
     Response Jresponse = Jsoup 
       .connect(ContactInfoURL).cookie("Website-session", cookie) 
       .data("firstname", firstName, "lastname", lastName, 
         "streetAddress", streeAdress, "careOfAddress", 
         coAdress, "zipCode", zipCode, "city", city, 
         "country", country, "phone", alternativPhone, 
         "languageForeignKey", language, 
         "invoiceDeliveryMethod", deliveryMethod, 
         "preferredMessageMethod", messageMethod, 
         "authenticity_token", token) 
       .method(Method.POST) 
       .execute(); 

我不知道是否需要標記,但我仍然使用它。我可以從之前獲取令牌,因此它與記錄的會話相同。每個函數所需的輸入都與表單相同,我只是將名字更改爲Johnnn以查看它是否有效,但約翰在網站上沒有更改。

回答

2

修好了!

頁面上有幾個按鈕(頂部的搜索欄和一些導航按鈕)。通過編輯代碼並添加我專注於解決問題的按鈕。新代碼:

esponse Jresponse = .connect(ContactInfoURL).cookie("Website-session", cookie) 
      .data("firstname", firstName, "lastname", lastName, 
        "streetAddress", streeAdress, "careOfAddress", 
        coAdress, "zipCode", zipCode, "city", city, 
        "country", country, "phone", alternativPhone, 
        "languageForeignKey", language, 
        "invoiceDeliveryMethod", deliveryMethod, 
        "preferredMessageMethod", messageMethod, "save_button", button, 
        "authenticity_token", token) 
       .method(Method.POST) 
       .execute(); 

所以通過基本上添加可以通過F12-> Chrome捕獲的按鈕名稱來修復它。 :)