| 57 | } |
| 58 | |
| 59 | int HttpClient::startRequest(const char* aServerName, uint16_t aServerPort, const char* aURLPath, const char* aHttpMethod, const char* aUserAgent) |
| 60 | { |
| 61 | tHttpState initialState = iState; |
| 62 | if ((eIdle != iState) && (eRequestStarted != iState)) |
| 63 | { |
| 64 | return HTTP_ERROR_API; |
| 65 | } |
| 66 | |
| 67 | #ifdef PROXY_ENABLED |
| 68 | if (iProxyPort) |
| 69 | { |
| 70 | if (!iClient->connect(iProxyAddress, iProxyPort) > 0) |
| 71 | { |
| 72 | #ifdef LOGGING |
| 73 | Serial.println("Proxy connection failed"); |
| 74 | #endif |
| 75 | return HTTP_ERROR_CONNECTION_FAILED; |
| 76 | } |
| 77 | } |
| 78 | else |
| 79 | #endif |
| 80 | { |
| 81 | if (!iClient->connect(aServerName, aServerPort) > 0) |
| 82 | { |
| 83 | #ifdef LOGGING |
| 84 | Serial.println("Connection failed"); |
| 85 | #endif |
| 86 | return HTTP_ERROR_CONNECTION_FAILED; |
| 87 | } |
| 88 | } |
| 89 | |
| 90 | // Now we're connected, send the first part of the request |
| 91 | int ret = sendInitialHeaders(aServerName, IPAddress(0,0,0,0), aServerPort, aURLPath, aHttpMethod, aUserAgent); |
| 92 | if ((initialState == eIdle) && (HTTP_SUCCESS == ret)) |
| 93 | { |
| 94 | // This was a simple version of the API, so terminate the headers now |
| 95 | finishHeaders(); |
| 96 | } |
| 97 | // else we'll call it in endRequest or in the first call to print, etc. |
| 98 | |
| 99 | return ret; |
| 100 | } |
| 101 | |
| 102 | int HttpClient::startRequest(const IPAddress& aServerAddress, const char* aServerName, uint16_t aServerPort, const char* aURLPath, const char* aHttpMethod, const char* aUserAgent) |
| 103 | { |