发送post请求 返回http 406错误

scenewood 2017-10-31 05:37:57
调用一个三方接口,返回错误代码406,百度谷歌都查过了,实在没办法了,只能发帖求助
    public function post_api(){
//测试商户号 013113052300
//测试密钥 j0x9skv6oujnrodqadpgdgtqdzbtg8ji

$url = "http://123.207.31.97:1083/pospay/gatewayPay";

$sing = 'api_type=GATEWAY&char_type=UTF-8&data=';
$sing.= '<xml>';
$sing.= '<mch__create__ip>139.199.172.76</mch__create__ip>';
$sing.= '<mch__trade__no>No20170710160025</mch__trade__no>';
$sing.= '<total__fee>1</total__fee>';
$sing.= '<product__name>xxx</product__name>';
$sing.= '<time__start>20170710160025</time__start>';
$sing.= '<return__url>http://139.199.172.76/Admin/Crj/recharge.html</return__url>';
$sing.= '<notify__url>http://139.199.172.76/Admin/Crj/recharge.html</notify__url>';
$sing.= '</xml>';
$sing.= '&data_type=xml&mch_id=013113052300&nonce_str=20170710160025&sign_type=MD5&ver_no=1.08n649qgjphde1l2qf83ri9094tddciky';
$sing_data = md5($sing);
$res = $this->request_post($url,$sing_data);
// $res = $this->CurlFile($url,$sing_data);
print_r($res);
}



public function request_post($url = '', $param = '') {
if (empty($url) || empty($param)) {
return false;
}
$postUrl = $url;
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$postUrl);//抓取指定网页
curl_setopt($ch, CURLOPT_HEADER,false);//设置header
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);//要求结果为字符串且输出到屏幕上
curl_setopt($ch, CURLOPT_POST, 1);//post提交方式
curl_setopt($ch, CURLOPT_POSTFIELDS, $param);
$data = curl_exec($ch);//运行curl
curl_close($ch);
return $data;
}



...全文
1599 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
scenewood 2017-10-31
  • 打赏
  • 举报
回复
             // 设置通用的请求属性
			conn.setRequestProperty("accept", "*/*");
			conn.setRequestProperty("connection", "Keep-Alive");
			conn.setRequestProperty("user-agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1)");
会不会是header错误呢 这段java代码转为php代码 该怎么写。。

20,360

社区成员

发帖
与我相关
我的任务
社区描述
“超文本预处理器”,是在服务器端执行的脚本语言,尤其适用于Web开发并可嵌入HTML中。PHP语法利用了C、Java和Perl,该语言的主要目标是允许web开发人员快速编写动态网页。
phpphpstorm 技术论坛(原bbs)
社区管理员
  • 开源资源社区
  • phpstory
  • xuzuning
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧