我用AJAX POST数据过去可以、、用curl怎么不行?
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_HEADER,0);
curl_setopt($ch,CURLOPT_POST,1);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch,CURLOPT_POSTFIELDS,$curlPost);
$data=curl_exec($ch);
curl_close($ch);
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_HEADER,0);
curl_setopt($ch,CURLOPT_POST,1);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch,CURLOPT_POSTFIELDS,$curlPost);
$data=curl_exec($ch);
curl_close($ch);
$url="http://www.ems.com.cn/tools/postageenresult.jsp";
$post_data=array(
'reqCode'=>'Postageen',
'goodsType'=>'goods',
'addressto'=>'阿根廷',
'weight'=>2);
$data= http_build_query($post_data);
$ch=curl_init($url);
curl_setopt($ch,CURLOPT_POST,1);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch,CURLOPT_POSTFIELDS,$data);
$result=curl_exec($ch);
curl_close($ch);
print_r($result);
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
</head>
<script language="javascript">
function makeRequest() {
http_request = false; if (window.XMLHttpRequest) {
http_request = new XMLHttpRequest();
if (http_request.overrideMimeType) {
http_request.overrideMimeType('text/xml');
}
} else if (window.ActiveXObject) { // IE
try {http_request = new ActiveXObject("Msxml2.XMLHTTP");} catch (e) {}
} if (!http_request) {
alert('不能创建 XMLHTTP 实例');
return false;
}
http_request.onreadystatechange = showfeeContents;
var urls="http://www.ems.com.cn/tools/postageenresult.jsp";
http_request.open('POST', urls, true);
http_request.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); var sendurl="";
var address="阿根廷";
var weights=2;
sendurl="reqCode=Postageen&goodsType=goods&addressto="+address+"&weight="+weights;
http_request.send(sendurl);
}
function showfeeContents() {
if (http_request.readyState == 4) { if (http_request.status == 200) {
var test=http_request.responseText;
alert(test);
}
else
{
alert('请求出错121.');
}
}
}
</script>
<body>
<span style=" cursor:pointer;" onclick="makeRequest()" >POST</span>
<div id="price"></div>
</body>
</html>Php的不行,html可以、、