第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

使用PHP讀取JSON帖子

使用PHP讀取JSON帖子

PHP
慕森王 2019-06-16 15:03:08
使用PHP讀取JSON帖子在發(fā)布這個問題之前,我看了很多遍,所以我很抱歉,如果它在另一個帖子上,這只是我在這里的第二個問題,所以如果我沒有正確地設(shè)置這個問題的格式,那么很抱歉。我已經(jīng)創(chuàng)建了一個非常簡單的Web服務(wù),需要獲取POST值并返回一個JSON編碼數(shù)組。這一切都很好,直到我被告知我需要用一個內(nèi)容類型的應(yīng)用程序/json發(fā)布表單數(shù)據(jù)。從那時(shí)起,我不能從Web服務(wù)返回任何值,這肯定與我如何過濾他們的POST值有關(guān)?;旧?,在我的本地設(shè)置中,我創(chuàng)建了一個測試頁面,它執(zhí)行以下操作-$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);在webservice上我有這個(我已經(jīng)刪除了一些功能)-<?phpheader('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 = array('statusCode'=>1, 'statusDescription'=>'Login Process - Fail');    $posts[] = array('status'=>$statusCode);    header('Content-type: application/json');    echo json_encode($posts);    /* disconnect from the db */}@mysql_close($link);?>基本上,我知道這是由于沒有設(shè)置$_post值,但是我找不到我需要放的東西,而不是$_post。我嘗試了json_decode($_post)、file_get_content(“php:/input”)和許多其他方式,但是我在黑暗中拍攝了一些東西。任何幫助都將不勝感激。
查看完整描述

3 回答

?
撒科打諢

TA貢獻(xiàn)1934條經(jīng)驗(yàn) 獲得超2個贊

您可以將json放入?yún)?shù)并發(fā)送它,而不是只將json放在頭文件中:

$post_string= 'json_param=' . json_encode($data);//open connection$ch = curl_init();//set the url, number of POST vars, POST datacu
rl_setopt($ch,CURLOPT_POST, 1);curl_setopt($ch,CURLOPT_POSTFIELDS, $post_string);curl_setopt($curl, CURLOPT_URL, ' 
.local/');  // Set the url path we want to call//execute post$result = curl_exec($curl);//see the results$json=json_decode($result,tr
ue);curl_close($curl);print_r($json);

在服務(wù)端,您可以將json字符串作為參數(shù):

$json_string = $_POST['json_param'];$obj = json_decode($json_string);

然后,您可以使用轉(zhuǎn)換后的數(shù)據(jù)作為對象。



查看完整回答
反對 回復(fù) 2019-06-16
  • 3 回答
  • 0 關(guān)注
  • 553 瀏覽

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號