I looked behind the scenes on a site(heavy jQuery-ajax/json) and was able to automate the login as well as a few other tasks using HttpWebRequest in c# WinForms. The process does a few Posts where parameters are needed, all successfully.
The problem comes in with one specific request. Below is the ajax code I found in the site that is giving me issue. I would expect this to work in my app but I just get WebException - 404 Not Found error when I send the request.
$.ajax({
type: 'POST',
url: switchUrl,
data: {
index: index,
xstoken: Cookie.read('xstoken')
},
global: false,
success: function(content) {
//code refreshes page here.
}
What would make the server return 404 when I request though my app, but not though the site itself? Am I possibly missing other parameters? I have used Chrome to look at what is sent but from what I can see I have everything.
- All Cookies are set, the 开发者_如何学运维other requests respond just fine.
- All requests are https, not sure if this matters.
- Tried different user agents.
Some points to check / experiment on:
- Check what the value of switchurl / index / Cookie xstoken is when this call succeeds
- see what the referer is and mimic that
- put the value of index and the Cookie xstoken into the POST body
IF that does not help put these into the switchurl as querystring
IF all that does not help use Fiddler (see http://www.fiddler2.com/fiddler2/) or Wireshark to capture the actual communication when it succeeds...
精彩评论