在OpenCart上读取HttpRequest发布数据 [英] Reading a HttpRequest post data on OpenCart
问题描述
我正在从C#windowsform应用程序向OpenCart商店发送HTTP请求.
I am sending a HTTP request from a C# windowsform application to an OpenCart store.
这是提琴手向我发送的邮件,看上去很正确.
This is what fiddler is showing that I'm sending, which looks correct.
这是我正在调用的OpenCart项目中的代码.
This is the code I have in my OpenCart project that I'm calling.
class ControllerEAOpenCartProducts extends ControllerEAOpenCart {
public function createProduct()
{
print_r($this->request);
}
}
print_r正在输出以下数据,这些数据似乎不包含我的任何JSON数据.
The print_r is outputting the following data which doesn't appear to be containing any of my JSON data.
请求的内容类型似乎也不正确,不应该像小提琴手的请求所示那样是application/json吗?
The content type of the requst also seems to be incorrect, shouldn't it be application/json like the request in fiddler shows?
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
)
)
推荐答案
看起来像opencart的request类包装了php的全局变量.这些仅在提交常规表单数据时填充.
Looks like opencart's request class wraps php's globals. These only get populated when regular form data is submitted.
要访问json,您需要使用较低级别的输入流:
To access json, you need to use the lower level input stream:
public function createProduct()
{
print_r(json_decode(file_get_contents('php://input'), true));
}
这篇关于在OpenCart上读取HttpRequest发布数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!