简单的PHP发布问题

编程入门 行业动态 更新时间:2024-10-25 17:20:50
本文介绍了简单的PHP发布问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

你好, 我正在尝试使用PHP网站提供的API,但是我遇到了问题.我可以在C#中很好地使用API​​. C3中的以下代码有效:

Hello, I am trying to use an API offered by a website in PHP however I am facing problems. I can use the API very fine in C#. The following code in C3 works:

string result = wb.UploadString(apiurl, "POST", "Hello, where do you live"); MessageBox.Show(result);

上面的代码可以完美地找到.但是我想用PHP编写相同的代码.在PHP中,我正在使用不带CURL的PHP​​中的HTTP POST,我也尝试过使用CURL,但是它不起作用,我没有从API返回任何信息. 以下是PHP代码:

The above code works perfectly find. But I want to make the same code in PHP. In PHP I am utilizing HTTP POST from PHP without CURL , I have tried with CURL as well but it just doesn''t work, I do not get anything returned from the API. The following is the PHP code:

function do_post_request($url, $data, $optional_headers = null) { $params = array('http' => array('method' => 'POST','content' => $data)); if ($optional_headers !== null) { $params['http']['header'] = $optional_headers; } $ctx = stream_context_create($params); echo $ctx['content']; $fp = @fopen($url, 'rb', false, $ctx); if (!$fp) { throw new Exception("Problem with $url, $php_errormsg"); } $response = @stream_get_contents($fp); if ($response === false) { throw new Exception("Problem reading data from $url, $php_errormsg"); } return $response; } $result = do_post_request($apiurl,$txtstr); echo $result;

我没有结果,也没有任何错误. 该API的严格条件是: 您应该将内容作为POST DATA,并且不要在POST DATA中写任何其他内容或参数 任何人都有什么想法可以帮助我吗? 关于

I get no result, Neither do I get any error. The API has strict condition that: you should put your content as the POST DATA, and don’t write any other content or parameters in the POST DATA Any one have any idea and can help me? Regards

推荐答案

url,

数据, data,

optional_headers = null) { optional_headers = null) {

更多推荐

简单的PHP发布问题

本文发布于:2023-10-10 22:31:14,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1479936.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:简单   PHP

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!