우리는 file_get_contents를 사용하여 사용자를 생성하는 웹 서비스와 통신하고, 성공하면 새로운 생성 된 사용자의 세부 정보가 담긴 JSON 객체를 반환합니다. 아래 코드는 사용자가 성공적으로 생성되었음을 보여줍니다. 즉, 백엔드에서 볼 수 있음을 의미하지만, JSON 응답을 얻을 수 없으며 아무 것도 반환하지 않습니다..file_get_contents가 웹 서비스에서 아무 것도 얻지 못하는 이유는 무엇입니까?
첫째 우리는 웹 서비스가 아무것도 돌려주지 않는 줄 알았는데, 그래서 우리는 우리가가 { "stutas"같은의 응답 만들 수있어 의미 완벽하게 잘 작동 C#을에 대해 테스트에서public function register(){
$username = "testing";
$email = "[email protected]";
$password = "testpsd";
$userData = '{"$xmlns": {"pluser": "http://xml.webservice.com/auth/data/User"},'
.'"pluser$userName": "'.$username.'",'
.'"pluser$password": "'.$password.'",'
.'"pluser$fullName": "fullname",'
.'"pluser$email": "'.$email.'"}';
$url = 'https://webservice.com?form=json';
$cparams = array('http' => array('method' => 'POST','ignore_errors' => true));
$cparams['http']['content'] = $userData;
$cparams['http']['request_fulluri'] = true;
$cparams['http']['header'] = 'Content-type: application/json';
$context = stream_context_create($cparams);
$fp = @file_get_contents($url,false,$context);$res = stream_get_contents($fp);
print_r($res);
}
: "성공을" "사용자 생성"
String url = "https://webservice.com?form=json";
HttpWebRequest req = (HttpWebRequest) WebRequest.Create(url);
req.Method = "POST";
string strRequest = "exactly the same json string";
req.ContentLength = strRequest.Length;
StreamWriter streamOut = new StreamWriter(req.GetRequestStream(), System.Text.Encoding.ASCII);
streamOut.Write(strRequest);
streamOut.Close();
StreamReader streamIn = new StreamReader(req.GetResponse().GetResponseStream());
while (!streamIn.EndOfStream)
Console.WriteLine(streamIn.ReadToEnd());
streamIn.Close();
Console.ReadKey();}
는 PHP 코드가 누락되거나 잘못 아무것도입니다 : "true"로} 여기에 C# 코드인가?
당신은 JSON 당신이 그것을'인 print_r (json_decode ($ userData에))를'사용 무슨 생각을 정말 것을 확인 했습니까? –
@ 피터, 마침내 컬을 사용하여이 문제를 해결할 수있었습니다. PHP 설정이 잘못되어 처음에는 컬이 작동하지 않았습니다. 수정 되 자마자 모든 것이 매력적이었습니다. 감사합니다. 어쨌든 – walter