我正在从C#windowsform应用程序向OpenCart商店发送HTTP请求。
这就是小提琴手正在发送的内容,看起来是正确的。
这是我正在调用的OpenCart项目中的代码。
class ControllerEAOpenCartProducts extends ControllerEAOpenCart {
public function createProduct()
{
print_r($this->request);
}
}
print_r输出的以下数据似乎不包含任何我的JSON数据。
请求的内容类型似乎也是不正确的,不应该像fiddler节目中的请求那样应用/ json吗?
Content-Type: text/html
HTTP/1.1 200 OK
Date: Wed, 04 Mar 2015 10:50:33 GMT
Server: Apache
Expires: Thu, 19 Nov 1981 08:52:00 GMT
Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0
Pragma: no-cache
Set-Cookie: PHPSESSID=23dbd33ede35cbeb5486054d06a773a2; path=/; HttpOnly
Set-Cookie: language=en; expires=Fri, 03-Apr-2015 10:50:33 GMT; path=/; domain=opencart.exact3ex.co.uk
Set-Cookie: currency=USD; expires=Fri, 03-Apr-2015 10:50:33 GMT; path=/; domain=opencart.exact3ex.co.uk
Set-Cookie: DYNSRV=lin170; path=/
Connection: close
Content-Type: text/html
Content-Length: 1826
Request Object
(
[get] => Array
(
[route] => EAOpenCart/Products/createProduct
)
[post] => Array
(
)
[cookie] => Array
(
)
[files] => Array
(
)
[server] => Array
(
[CONTENT_LENGTH] => 200
[CONTENT_TYPE] => application/json
[DOCUMENT_ROOT] => /var/sites/o/opencart.exact3ex.co.uk/public_html
[GATEWAY_INTERFACE] => CGI/1.1
[HTTP_CONNECTION] => close
[HTTP_EXPECT] => 100-continue
[HTTP_HOST] => opencart.exact3ex.co.uk
[HTTP_X_FORWARDED_FOR] => 194.143.179.2
[PATH] => /bin
[QUERY_STRING] => route=EAOpenCart/Products/createProduct
[REDIRECT_STATUS] => 200
[REMOTE_ADDR] => 194.143.179.2
[REMOTE_PORT] => 60376
[REQUEST_METHOD] => POST
[REQUEST_URI] => /?route=EAOpenCart/Products/createProduct
[SCRIPT_FILENAME] => /var/sites/o/opencart.exact3ex.co.uk/public_html/index.php
[SCRIPT_NAME] => /index.php
[SERVER_ADDR] => 10.168.1.170
[SERVER_ADMIN] => you@example.com
[SERVER_NAME] => opencart.exact3ex.co.uk
[SERVER_PORT] => 80
[SERVER_PROTOCOL] => HTTP/1.1
[SERVER_SIGNATURE] =>
[SERVER_SOFTWARE] => Apache
[PHP_SELF] => /index.php
[REQUEST_TIME_FLOAT] => 1425466233.43
[REQUEST_TIME] => 1425466233
[argv] => Array
(
[0] => route=EAOpenCart/Products/createProduct
)
[argc] => 1
[HTTPS] =>
)
[request] => Array
(
[route] => EAOpenCart/Products/createProduct
)
)
答案 0 :(得分:2)
看起来opencart的请求类包装了php的全局变量。只有在提交常规表单数据时才会填充这些内容。
要访问json,您需要使用较低级别的输入流:
public function createProduct()
{
print_r(json_decode(file_get_contents('php://input'), true));
}