PHP cURL Submitting POST data, multipart/form
So I have a site that I am building and it will be using data in a database to fill out forms on different websites. Now I understand that this can easily be done with cURL or python however when I intercept and read the post data it is usually a huge mess. For instance on this form there is only a option for comment and rating yet contains all types of other garbage:
-----------------------------122061295120255 Content-Disposition: form-data; name="StylesheetManager_TSSM"This is not a website I would be posting to however it is a very good representation of what I'm dealing with for the kinds of sites I'll be working with. I understand how to post using the multipart/form-data however what do I do for fields such as "__EVENTVALIDATION"?-----------------------------122061295120255 Content-Disposition: form-data; name="ScriptManager_TSM"
-----------------------------122061295120255 Content-Disposition: form-data; name="__EVENTTARGET"
dnn$ctr459$viewNukeNews$ctl00$ctlViewNewsComments$lbSaveCommentsRating -----------------------------122061295120255 Content-Disposition: form-data; name="__EVENTARGUMENT"
-----------------------------122061295120255 Content-Disposition: form-data; name="__VIEWSTATE"
e938BM4vVlpM3W+nCswl1rBoQfFc4nBTmKwOSecEbbEU2NDYATm/kCix79QXoW+tZGED7vRe6DIpcv+r8R5dwtCCtCTG5bBJ7EgOAC0HD20XVgmqgNfd3zwiVH3hhYjW9TTPTtwNgPigqfthwmEijBiu8KVc7j/UqHTHti3e5VnRy/YjRxYTGUW5OEr15UHsHDK3fsGAMjzXEcvnzHELCzioBR76DmTpQQECJrRBD8phmoghyUWFU/uFQAfx4r83Q0eHTGv8MevBfrcokPlIkokgOKGinW3fjvdcTxF4peXoaD5iBlBS2eFFZwLZEXcNsOx1ttQQPKYueISssK02TTEg5vhaSSXzwUuEdfYHPdlBZB8TrjEtSAq8Y1OB4FtWtMYtgbAM17052yz9r+eEljLDCfnEAJBQw+Z7OfDu4FLnxuScTeci7K9x85p5sX8ggLOGCufCeO8zSNLsktMa29mOipYLlHDevicer+6pUfZIAUJyJ8nqxzUUMTu3s85H9TG7Ct2fUqO+JMvRygLcTo1NS3DPaHzNaTnDHtreZJ6tnHeE5lMg/pdg4dqTgNg5yLiDhvmbu+N3NAHvbw4ES/fheVqFt32LZMPjZC++xgcOMIyWPHlOFYKY3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nUwgySV+M5Z/XWpKErvV9f7Gxfgr/g8vVRWo+crm9wsMScI8Mxbc1pGGMQcy3C1bNGQ6X0Bm+vke7TMkRaH7rRsZh/SJGMQQg1ie3CYpFmHk+vP/OS7H/i4tHyblJ+yPCwcACIM72JaBYnqjfLMQuA34FT0M3Rvk9vZhsRaA6HnLj12EsSssENCYZWScf2XEx8JfTePyIvs5al+Nal1bm2On0o44ZMJ31pc8K0iKBc9ig== -----------------------------122061295120255 Content-Disposition: form-data; name="__VIEWSTATEGENERATOR"
CA0B0334 -----------------------------122061295120255 Content-Disposition: form-data; name="__VIEWSTATEENCRYPTED"
-----------------------------122061295120255 Content-Disposition: form-data; name="__EVENTVALIDATION"
tA4eGr1Xgh239z393i4iChEPuFYs10biEg4Ym9fZu0aLDt7H4yWECsFXKjtzX7fHWn9WDNOm4a+nPf+qka4hzEpBfm3zRotMOrkEzCm61aM+pbZgaqhQjMPpsDhT3t6k8NkeqaSkUIyFKbXYkpx4GTyyCk0s3UPlqFR8klie6NTAkt0qPH5cjc0GzVRmMBZ5GTbA+L4oGOCgDFpCZ7SFU+/VS+37gRU3YarzwmelKqRNYutT9MwJc5beUUxCNBm6r2Zdeb8OnQnpZR2KlNT8EP+x5+Wsj9Q738H7jX5p2rCNEqmH6mK1wAVM5Rqzo8JTFdtQ6da7PAi9uMj89Vq+LXlf/6BR9vlpEk1cozY9Ny4xdZr8xKSVUYcuJYQ= -----------------------------122061295120255 Content-Disposition: form-data; name="dnn$dnnSEARCH$txtSearch"
-----------------------------122061295120255 Content-Disposition: form-data; name="dnn$ctr459$viewNukeNews$ctl00$ctlViewNewsComments$rblRating"
3 -----------------------------122061295120255 Content-Disposition: form-data; name="dnn$ctr459$viewNukeNews$ctl00$ctlViewNewsComments$tbComments"
COMMENT GOES HERE -----------------------------122061295120255 Content-Disposition: form-data; name="ScrollTop"
260 -----------------------------122061295120255 Content-Disposition: form-data; name="__dnnVariable"
{"__scdoff":"1","containerid_dnn_ctr459_ModuleContent":"459","cookieid_dnn_ctr459_ModuleContent":"_Module459_Visible","min_icon_459":"/Portals/_default/Containers/Apple-Orange/min.gif","max_icon_459":"/Portals/_default/Containers/Apple-Orange/max.gif","max_text":"Maximize","min_text":"Minimize"} -----------------------------122061295120255--
Edit: Added code that will be used
function post_data($site,$data){ $datapost = curl_init(); $headers = array("Content-Type: multipart/form-data; boundary=---------------------------86732602411937"); curl_setopt($datapost, CURLOPT_URL, $site); curl_setopt($datapost, CURLOPT_TIMEOUT, 40000); curl_setopt($datapost, CURLOPT_HEADER, TRUE); curl_setopt($datapost, CURLOPT_HTTPHEADER, $headers); curl_setopt($datapost, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']); curl_setopt($datapost, CURLOPT_POST, TRUE); curl_setopt($datapost, CURLOPT_POSTFIELDS, $data); curl_setopt($datapost, CURLOPT_COOKIEFILE, "cookie.txt"); ob_start(); return curl_exec ($datapost); ob_end_clean(); curl_close ($datapost); unset($datapost);
}
I have dealt with these types of forms before. They are a pain. What I do is:
Oh and sometimes there are fields like __EVENTTYPE that need to be set to a certain string for the event you want. To help break down what your second curl should look like, use Chrome developer tools to look at the Request nicely parsed. You can even copy it as a cURL.
链接地址: http://www.djcxy.com/p/48898.html上一篇: 数据到php 5.4.3露天