簡體   English   中英

如何在php中發送get請求並接收json數據

[英]How to send a get request and recieve json data in php

我實際上想知道如何在 php 中創建這個請求

GET /current_user HTTP/1.1
Host: localhost
User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:52.0) Gecko/20100101 Firefox/52.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: en-US,en;q=0.5
Accept-Encoding: gzip, deflate, br
Referer: http://burp/show/1
X-Requested-With: XMLHttpRequest
Cookie: ...
Connection: close
Upgrade-Insecure-Requests: 1

添加行非常重要

X-Requested-With: XMLHttpRequest

在請求中,我還需要獲得像這樣的 json 響應

{"csrf_token":"..............","signed_in?":true,"disclosure_directory_submissions_enabled":false,"new_feature_article_available":false,"bounty_statistics_enabled":true,"pro_community_enabled":false,"davr_enabled":false,"is_member_of_teams":false,"can_request_endorsements":false,"whitelisted_team_ids":[],"edit_unclaimed_profiles":false,"signal":null,"email":"........","id":.....,"username":"....","name":"Mohamed Sherif","bio":"","url":".","profile_picture_urls":{"small":"..","medium":".."}}

非常感謝你的幫助

可以使用 curl 正常發送請求。 對於傳遞標頭,請使用以下示例:

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,"http://localhost/current_user");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); //to get return value from server

curl_setopt($ch, CURLOPT_HTTPHEADER, array(
    'X-Requested-With: XMLHttpRequest'
));
$output = curl_exec ($ch);
curl_close ($ch);
echo $output;

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM