我在发布数据时遇到问题。我作为anweser“415 Unsupported Media Type”获得了。 我可以获取数据,但如果我发布,我会收到“415不支持的媒体类型”。
欢迎任何帮助!
下面你可以看到错误的请求以及HEADER和POST:
Anweser:
HTTP / 1.1 400错误请求X-content-type-options:nosniff X-xss-protection:1; mode = block Pragma:no-cache X-frame-options:DENY Set-cookie: HTTP错误:400
部首:
$httpClient -> setHeaders(array(
"Content-Type : application/json; charset=utf-8",
"Accept : application/json",
"SM_USER :". $authToken,
"Accept-Language : de"
));
POST,GET:
switch($requestType) {
case "get":
$restRes = $this->restClient->restGet($path,$queryParameter);
$result = $this->_handleRestResult($restRes);
return $result;
break;
case "post":
$restRes = $this->restClient->restPost($path,$queryParameter);
break;
case "delete":
case "put":
}
QUERYPARAMETER
$query = json_encode(array(
"latitude" => $lat,
"longitude" => $long,
"service" => $service
));
PATH
$path = $this-service->rest->path."/resource/Service/";
答案 0 :(得分:1)
我们不能使用$ this-> restClient-> restPost,因为它会重置整个 潜在的Http_Client再次! 这具体意味着它会重置我们使用的标头。 所以我们自己做所有的步骤。
switch($requestType) {
case "post":
$httpClient->setUri($this->_config->service->rest->host."".$path);
$httpClient->setMethod('POST');
$httpClient->setRawData($queryParameter, $httpClient->getHeader('Content-Type'));
$restRes = $httpClient->request($method);
$this->restClient->getHttpClient()->getHeader('Content-Type'));
print_r($this->restClient->getHttpClient()->getHeader('Accept'));
print_r($this->restClient->getHttpClient()->getLastRequest());
print_r($restRes);
print_r($this->restClient->getHttpClient()->getLastResponse());
$result = $this->_handleRestResult($restRes);
return $result;
break;
break;
case "delete":
//
case "put":
//
default:
case "get":
$restRes = $this->restClient->restGet($path,$queryParameter);
$result = $this->_handleRestResult($restRes);
return $result;
break;
}