大家好
我正在尝试使用 http_client_demo 示例实现 get 方法、
在使用 "httpbin.org 和"/get"进行测试时、它工作正常、我获得200个状态、
但是、对于我自己的主机、我失败了(404或302)、尽管它可以与 postman 和我的 Chrome 浏览器一起使用、但为什么会收到一个可以与 Postman 一起使用的地址请求、那么我的 CC3200上会返回404或302的状态?
谢谢
This thread has been locked.
If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.
大家好
我正在尝试使用 http_client_demo 示例实现 get 方法、
在使用 "httpbin.org 和"/get"进行测试时、它工作正常、我获得200个状态、
但是、对于我自己的主机、我失败了(404或302)、尽管它可以与 postman 和我的 Chrome 浏览器一起使用、但为什么会收到一个可以与 Postman 一起使用的地址请求、那么我的 CC3200上会返回404或302的状态?
谢谢
您好、Sabeeh、
好的、这是我的"Get"方法测试代码:
#define APPLICATION_VERSION "1.4.0" #define APP_NAME "HTTP Client" #define POST_REQUEST_URI "/post" //#define POST_REQUEST_URI "/info.0.json" #define POST_REQUEST_URI "/metadata/TheAdventuresOfTomSawyer_201303" #define POST_DATA "{}" #define DELETE_REQUEST_URI "/delete" #define PUT_REQUEST_URI "/put" #define PUT_DATA "PUT request." #define GET_REQUEST_URI "/get" #define HOST_NAME "httpbin.org" //"<host name #define HOST_NAME_GET "www.amudraa.com" #define GET_REQUEST_URI_TERMINAL "/terminal" static int HTTPGetAmudMethod(HTTPCli_Handle httpClient) { long lRetVal = 0; HTTPCli_Field fields[4] = { {HTTPCli_FIELD_NAME_HOST, HOST_NAME_GET}, {HTTPCli_FIELD_NAME_ACCEPT, "*/*"}, {HTTPCli_FIELD_NAME_CONTENT_LENGTH, "0"}, {NULL, NULL} }; bool moreFlags; /* Set request header fields to be send for HTTP request. */ HTTPCli_setRequestFields(httpClient, fields); /* Send GET method request. */ /* Here we are setting moreFlags = 0 as there are no more header fields need to send at later stage. Please refer HTTP Library API documentaion @ HTTPCli_sendRequest for more information. */ moreFlags = 0; lRetVal = HTTPCli_sendRequest(httpClient, HTTPCli_METHOD_GET, GET_REQUEST_URI_TERMINAL, moreFlags); if(lRetVal < 0) { UART_PRINT("Failed to send HTTP GET request.\n\r"); return lRetVal; } lRetVal = readResponse(httpClient); return lRetVal; } //***************************************************************************** // //! \brief HTTP GET Demonstration //! //! \param[in] httpClient - Pointer to http client //! //! \return 0 on success else error code on failure //! //***************************************************************************** static int HTTPGetMethod(HTTPCli_Handle httpClient) { long lRetVal = 0; HTTPCli_Field fields[4] = { {HTTPCli_FIELD_NAME_HOST, HOST_NAME}, {HTTPCli_FIELD_NAME_ACCEPT, "*/*"}, {HTTPCli_FIELD_NAME_CONTENT_LENGTH, "0"}, {NULL, NULL} }; bool moreFlags; /* Set request header fields to be send for HTTP request. */ HTTPCli_setRequestFields(httpClient, fields); /* Send GET method request. */ /* Here we are setting moreFlags = 0 as there are no more header fields need to send at later stage. Please refer HTTP Library API documentaion @ HTTPCli_sendRequest for more information. */ moreFlags = 0; lRetVal = HTTPCli_sendRequest(httpClient, HTTPCli_METHOD_GET, GET_REQUEST_URI, moreFlags); if(lRetVal < 0) { UART_PRINT("Failed to send HTTP GET request.\n\r"); return lRetVal; } lRetVal = readResponse(httpClient); return lRetVal; } int main() { long lRetVal = -1; HTTPCli_Struct httpClient; // // Board Initialization // BoardInit(); // // Configure the pinmux settings for the peripherals exercised // PinMuxConfig(); // // Configuring UART // InitTerm(); // // Display banner // DisplayBanner(APP_NAME); InitializeAppVariables(); lRetVal = ConnectToAP(); if(lRetVal < 0) { LOOP_FOREVER(); } lRetVal = ConnectToHTTPServer(&httpClient); if(lRetVal < 0) { LOOP_FOREVER(); } //--------------------------- UART_PRINT("\n\r"); UART_PRINT("HTTP Get BIN Begin:\n\r"); lRetVal = HTTPGetBinMethod(&httpClient); if(lRetVal < 0) { UART_PRINT("HTTP Post Get Bin failed.\n\r"); } UART_PRINT("HTTP Get Bin End:\n\r"); UART_PRINT("\n\r"); //--------------------------- UART_PRINT("\n\r"); UART_PRINT("HTTP Get Amud Begin:\n\r"); lRetVal = HTTPGetAmudMethod(&httpClient); if(lRetVal < 0) { UART_PRINT("HTTP Post Get Amud failed.\n\r"); } UART_PRINT("HTTP Get Amud End:\n\r"); UART_PRINT("\n\r");
这是终端:(我已编辑我的 wifi 网络名称和 IP )的结果
************************************************* CC3200 HTTP Client Application ************************************************* Host Driver Version: 1.0.1.14 Build Version 2.11.0.1.31.1.5.0.2.1.0.3.37 Device is configured in default state Device started as STATION [WLAN EVENT] STA Connected to the AP: ------ , BSSID: f0:b0:14:2f:4c:d7 [NETAPP EVENT] IP Acquired: IP=------ , Gateway=192.168.178.1 Connected to the AP: ------ Connection to server created successfully HTTP Get BIN Begin: HTTP getResponseStatus 200 HTTP Status 200 Content-Type : application/json=1 Successfully parsed 17 JSON tokens HTTP Get Bin End: HTTP Get Amud Begin: HTTP getResponseStatus 404 File not found. HTTP Get Amud End:
谢谢!
你(们)好,Rogelio
这是实现方案、这正是我尝试的另一个示例-连接到"httpbin.org",as、我在 使用 "httpbin.org 和"/get"进行测试时说过、它可以正常工作、我获得200个状态、
#define HOST_NAME_BIN "httpbin.org" #define GET_REQUEST_URI_BIN "/get" static int HTTPGetBinMethod(HTTPCli_Handle httpClient) { long lRetVal = 0; HTTPCli_Field fields[4] = { {HTTPCli_FIELD_NAME_HOST, HOST_NAME_BIN}, {HTTPCli_FIELD_NAME_ACCEPT, "*/*"}, {HTTPCli_FIELD_NAME_CONTENT_LENGTH, "0"}, {NULL, NULL} }; bool moreFlags; /* Set request header fields to be send for HTTP request. */ HTTPCli_setRequestFields(httpClient, fields); /* Send GET method request. */ /* Here we are setting moreFlags = 0 as there are no more header fields need to send at later stage. Please refer HTTP Library API documentaion @ HTTPCli_sendRequest for more information. */ moreFlags = 0; lRetVal = HTTPCli_sendRequest(httpClient, HTTPCli_METHOD_GET, GET_REQUEST_URI_BIN, moreFlags); if(lRetVal < 0) { UART_PRINT("Failed to send HTTP GET request.\n\r"); return lRetVal; } lRetVal = readResponse(httpClient); return lRetVal; }
问题是从 www.amudraa.com/terminal"实现了"get"、正如我说过的、它通过 Postman 工作
谢谢
Amud、您好!
您的主机是 http 还是 https?
如果是 https、我会查看这些 e2e 线程。
此致、
Rogelio