关于HttpWebRequest 连接能访问,提交后出现404
网页源代码:(没有form标签)
<input id="inputCode" name="inputCode" class="inputW64H24 " type="text" size="4" maxlength="4" style="ime-mode: disabled;">
<img id="captchaImg" name="captchaImg" style="border:1px #000000 solid;cursor:pointer;" width="100" height="30" src="/mall-web/Captcha?configKey=ZJ2t2ofiM9Ikpv4JE8Dctg%3D%3D" alt="关于HttpWebRequest 联接能访问,提交后出现404" />
<a id="changeVerifyCode" name="changeVerifyCode" style="cursor: pointer;cursor:hand;" class="fontC36cS12">换一张</a>
<input type="hidden" name="configKey" value="ZJ2t2ofiM9Ikpv4JE8Dctg==" />
网页js:
<script>
;document.domain = "10010.com";
$(function(){
$("#toCheckCaptcha").click(function(){
var params ={};
params.inputCode = $('#inputCode').val();
params.configKey ="ZJ2t2ofiM9Ikpv4JE8Dctg==";
$.ajax({
url: '/mall-web/OlympicActivityCaptcha/check',
type: 'POST',
data: params,
async: false,
success:function (jsonVerErr){
var errMsgContent = jsonVerErr.captchaResult;
if(errMsgContent == undefined || errMsgContent == ""){
$('#windownbg', window.parent.document).hide();
$('#windown-box', window.parent.document).hide();
}else if($.trim(errMsgContent)!= ""){
$("#verEssMsg").text("验证码输入错误");
$("#verificationError").show();
$('#changeVerifyCode').click();
return false;
}
}
});
})
})
</script>
HttpWebRequest请求:
string postData = "inputCode="+this.textBox3.Text;//验证码
postData += ("&configKey=ZJ2t2ofiM9Ikpv4JE8Dctg==");
request =
(HttpWebRequest)WebRequest.Create("http://www.10010.com/mall-web/OlympicActivityCaptcha/check");
Encoding encoding = Encoding.GetEncoding("utf-8");
byte[] data = encoding.GetBytes(postData.ToString());
request.ContentType = "text/html";
request.UserAgent = "Mozilla/5.0 (Windows NT 6.1; rv:14.0) Gecko/20100101 Firefox/14.0.1";
request.ContentLength = data.Length;
request.Referer = "http://www.10010.com/mall-web/OlympicActivityCaptcha/input";
request.CookieContainer = cookie;
request.Host = "10010.com";
request.Timeout = 10000;
request.Accept = "zh-CN";
request.Method = "POST";
Stream newStream = request.GetRequestStream();
Application.DoEvents();
// Send the data.
newStream.Write(data, 0, data.Length);
newStream.Close();
response = (HttpWebResponse)request.GetResponse();//404错误
string url = response.ResponseUri.ToString();
StreamReader reader = new StreamReader(response.GetResponseStream(), Encoding.GetEncoding("utf-8"));
抓包数据:
==========================Hear:
(Request-Line)POST /mall-web/OlympicActivityCaptcha/check HTTP/1.1
Hostwww.10010.com
User-AgentMozilla/5.0 (Windows NT 6.1; rv:14.0) Gecko/20100101 Firefox/14.0.1
Accept*/*
Accept-Languagezh-cn,zh;q=0.8,en-us;q=0.5,en;q=0.3
Accept-Encodinggzip, deflate
Connectionkeep-alive
Content-Typeapplication/x-www-form-urlencoded; charset=UTF-8
X-Requested-WithXMLHttpRequest
Refererhttp://www.10010.com/mall-web/OlympicActivityCaptcha/input
Content-Length53
Cookie略。。。。
Pragmano-cache
Cache-Controlno-cache