我需要使用 JSON 对象作为主体发出 POST 请求。这两种方法都给我 HTTP 500 服务器错误。我的代码有什么明显的错误吗?温柔点……我试过几种方法,包括
$checkfor = ("'serverId':'Server','featureId':'Feature','propertyId':'Property'");
$checkforJson = json_encode($checkfor);
$uri = "http://localhost:8080/v1/properties";
$response = \Httpful\Request::post($uri)
->method(Request::post)
->withoutStrictSsl()
->expectsJson()
->body($checkforJson)
->send();
pre($response);
Run Code Online (Sandbox Code Playgroud)
它使用 HTTPful 资源。我试过使用 cURL
$service_url = "http://localhost:8080/v1/properties";
// Initialize the cURL
$ch = curl_init($service_url);
// Set service authentication
// Composing the HTTP headers
$body = array();
$body[] = '"serverId" : "Server"';
$body[] = '"featureId" : "Feature"';
$body[] = '"propertyId" : "Property"';
$body = json_encode($body);
$headers = array();
$headers[] = 'Accept: application/xml';
$headers[] = 'Content-Type: …Run Code Online (Sandbox Code Playgroud)