相关疑难解决方法(0)

PHP + curl,HTTP POST示例代码?

任何人都可以告诉我如何使用HTTP POST进行PHP卷曲吗?

我想发送这样的数据:

username=user1, password=passuser1, gender=1
Run Code Online (Sandbox Code Playgroud)

www.domain.com

我希望curl能够返回响应result=OK.有什么例子吗?

php curl http http-post

454
推荐指数
10
解决办法
101万
查看次数

使用PHP阅读JSON POST

在发布这个问题之前我环顾了很多,所以我很抱歉,如果是在另一个帖子上,这只是我在这里的第二个问题,如果我没有正确地格式化这个问题,那么道歉.

我有一个非常简单的Web服务,我创建了它需要获取post值并返回一个JSON编码的数组.一切正常,直到我被告知我需要发布带有内容类型的application/json的表单数据.从那时起,我无法从Web服务返回任何值,这肯定与我如何过滤他们的帖子值有关.

基本上在我的本地设置中,我创建了一个测试页面,它执行以下操作 -

$curl = curl_init();
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "POST");                                                                     
curl_setopt($curl, CURLOPT_POSTFIELDS, $data);                                                                  
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);                                                                      
curl_setopt($curl, CURLOPT_HTTPHEADER, array(                                                                          
    'Content-Type: application/json',                                                                                
    'Content-Length: ' . strlen($data))                                                                       
);
curl_setopt($curl, CURLOPT_URL, 'http://webservice.local/');  // Set the url path we want to call
$result = curl_exec($curl);

//see the results
$json=json_decode($result,true);
curl_close($curl);
print_r($json);
Run Code Online (Sandbox Code Playgroud)

在网络服务上我有这个(我已经删除了一些功能) -

<?php

header('Content-type: application/json');

/* connect to the db */
$link = mysql_connect('localhost','root','root') or die('Cannot connect to the DB');
mysql_select_db('webservice',$link) or die('Cannot select the DB');

if(isset($_POST['action']) && $_POST['action'] == 'login') {
    $statusCode …
Run Code Online (Sandbox Code Playgroud)

php post json

57
推荐指数
1
解决办法
16万
查看次数

标签 统计

php ×2

curl ×1

http ×1

http-post ×1

json ×1

post ×1