我收到了以下卷曲请求:
curl -H "Content-Type:application/json" -H "Api-Key:someapikey" -X -d {"address":"30598 West Street","city":"Oakdale"}' PUT "https://somedomain/api/members/1234567"
我试图用GuzzleHttp复制它,如下所示:
$headers = [
'Api-Key' => $this->apiKey,
'Content-Type' => 'application/json',
];
$client = new Client([
'headers' => $headers,
]);
$res = $client->put("{$this->baseUrl}/members/{$fields['vip_id']}", [
'form_params' => $fields,
]);
我继续获得415不支持的媒体类型响应。从卷曲中我得到了我认为我已经覆盖了所有的基础。但是,当我调试时,它显示我的内容类型设置为application/x-www-form-urlencoded
。根据文档,仅当Content-Type标头尚未设置且包含form_params时,标头才会设置为此标头。由于我已经设置了这个标题,它不应该正确切换?请帮忙!
答案 0 :(得分:1)
您的标头被覆盖的原因是因为请求的#include <iostream>
#include <cuda_runtime.h>
void* operator new[] (size_t len) throw(std::bad_alloc) {
void *ptr;
cudaMallocManaged(&ptr, len);
return ptr;
}
template<typename T>
T**** create_4d(int a, int b, int c, int d){
T**** ary = new T***[a];
for(int i = 0; i < a; ++i)
{
ary[i] = new T**[b];
for(int j = 0; j < b; ++j){
ary[i][j] = new T*[c];
for(int k = 0; k < c; ++k){
ary[i][j][k] = new T[d];
}
}
}
return ary;
}
int main() {
double ****data;
std::cout << "allocating..." << std::endl;
data = create_4d<double>(32,65,65,5);
std::cout << "Hooreey !!!" << std::endl;
//segfault here
std::cout << "allocating..." << std::endl;
data = create_4d<double>(64,65,65,5);
std::cout << "Hooreey !!!" << std::endl;
return 0;
}
选项专门用于发送form_params
数据。
您可以完全省略选项中的x-www-form-urlencoded
标头,而是使用请求中的Content-Type
键发送JSON数据。
json