   Help wanted on HttpSendRequest
  Hello! I am trying to send a XML request to a server, but met a problem when execute the HttpSendRequest function.The problem comes from the server name "https://sapi.ock.com". Could you please let me know how to solve it? Thanks a lot in advance!#include <Windows.h>#include <WinINet.h>#include <stdio.h>void main( ){DWORD dwPostSize;int Size = 1024;char * Server = "https://sapi.ock.com";char * Path = "/test/aa.xml";dwPostSize = Size * 1024;  // Convert KB to bytesHINTERNET hSession = InternetOpen( "HttpSendRequest", INTERNET_OPEN_TYPE_PRECONFIG, 0, 0, 0);if(!hSession){printf("Failed to open session\n");exit(0);}char pBuffer[1024];FILE *fp = fopen("C:/XML/xmltst.xml", "r");fgets(pBuffer, sizeof(pBuffer),fp);    HINTERNET hConnect = InternetConnect(hSession, Server, INTERNET_DEFAULT_HTTP_PORT,0, 0, INTERNET_SERVICE_HTTP,0, 0);if (!hConnect) {printf( "Failed to connect\n" );return;}HINTERNET hRequest = HttpOpenRequest(hConnect, "PUT", Path,  0, 0, 0, INTERNET_FLAG_NO_CACHE_WRITE, 0);if (!hRequest) {printf( "Failed to open request handle\n" );return ;}BOOL bSenReq = HttpSendRequest (hRequest, NULL, 0, pBuffer, lstrlen (pBuffer));if (! bSenReq){   printf( "Error on HttpSendRequest %d\n\n",GetLastError() );return ;}    if(!HttpEndRequest(hRequest, 0, 0, 0))   printf( "Error on HttpEndRequest %lu \n", GetLastError());if (!InternetCloseHandle(hRequest))printf( "Failed to close Request handle\n" );if(!InternetCloseHandle(hConnect))printf("Failed to close Connect handle\n");if( InternetCloseHandle( hSession ) == FALSE )printf( "Failed to close Session handle\n" );}   
  One problem (I'm not sure it's the only one) is that you're passing a URL instead of a hostname. Change "https://sapi.ock.com" to "sapi.ock.com"   ;  Thanks Extrarius for your quick reply.If I use "sapi.ock.com" it means "http://sapi.ock.com", but the address should be "https://sapi.ock.com".Quote:Original post by ExtrariusOne problem (I'm not sure it's the only one) is that you're passing a URL instead of a hostname. Change "https://sapi.ock.com" to "sapi.ock.com";  After I modified the HttpOpenRequest() to osupport HTTPS, the same problem exist, does any one can help me? Thanks a lot!HINTERNET hRequest = HttpOpenRequest(hConnect, "POST", Path,  0, 0, 0, INTERNET_FLAG_KEEP_CONNECTION | INTERNET_FLAG_SECURE, 0);   ;  up   ;  What's the actual error you're getting? Can you post the current source you're using, as well as the function call that looks like it is failing?   ;  Thanks for your reply.The current code is:#include <Windows.h>#include <WinINet.h>#include <stdio.h>void main( ){DWORD dwPostSize;int Size = 1024;   char * Server = "https://sapi.ock.com";char * Path = "/test/aa.xml";dwPostSize = Size * 1024;  // Convert KB to bytesHINTERNET hSession = InternetOpen(0,INTERNET_OPEN_TYPE_PRECONFIG, 0, 0, 0);if(!hSession){printf("Failed to open session\n");exit(0);}char pBuffer[1024];FILE *fp = fopen("C:/XML/xmltst.xml", "r");fgets(pBuffer, sizeof(pBuffer),fp);   HINTERNET hConnect = InternetConnect(hSession, Server, INTERNET_DEFAULT_HTTPS_PORT, "", "", INTERNET_SERVICE_HTTP,0 ,0);if (!hConnect) {printf( "Failed to connect\n" );return;}HINTERNET hRequest = HttpOpenRequest(hConnect, "POST", Path,  HTTP_VERSION, 0, 0, INTERNET_FLAG_SECURE, 0); // HTTPSif (!hRequest) {printf( "Failed to open request handle\n" );return ;}BOOL bSenReq = HttpSendRequest (hRequest, 0, 0, pBuffer, lstrlen (pBuffer));if (! bSenReq){   printf( "Error on HttpSendRequest %d\n\n",GetLastError() );return ;}...}Error message is :Error on HttpSendRequestEx -- 12007Quote:Original post by ApochPiQWhat's the actual error you're getting? Can you post the current source you're using, as well as the function call that looks like it is failing?;  I realise it's HTTPS, but have you tried using a packet sniffer / monitor to watch the conversation?My browser wasn't able to get anything useful out of https://sapi.ock.com/ but of course you may have special permission to use it etc.Also, looking at ock.com, it looks suspiciously like the domain has been parked at a domain parking / domain name speculator's site.Doing DNS lookups, there seems to be a wildcard DNS on ock.com which gives back the same IP address for every .ock.com address - this is of course, not what I'd expect if it was hosted properly.Are you sure that your HTTPS server on https://sapi.ock.com is working right?Mark   ;  Further to my last post, it appears to my that the HTTPS server on https://sapi.ock.com:443/ is misconfigured, and is trying to speak HTTP.I tried to connect with the openssl s_client application and used Ethereal to watch the session, the server (which I had expected to try to speak SSL) said this:<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN"><html><head><title>501 Method Not Implemented</title></head><body>Method Not Implemented..... to /index.html.en not supported.<br /><address>Apache/2.0.52 (Unix) mod_ssl/2.0.52 OpenSSL/0.9.7e PHP/4.3.10 Server at traffic1.domainsystems.com Port 80</address></body></html>Which surprised me.Mark   ;  Thank you so much Mark for your replies.The server actually should be :char * Server = "https://sapidev.overstock.com/shoppingApi/api";or char * Server = "https://sapidev.overstock.com";without usr name and pwd.I just want to make it shorter. sorry for this.The following is the current cource code using HttpSendRequestEx:#include <Windows.h>#include <WinINet.h>#include <stdio.h>BOOL UseHttpSendReqEx(HINTERNET hRequest);#define BUFFSIZE 500void main( ){char pcBuffer[BUFFSIZE];DWORD dwBytesRead;char * Server = "https://sapidev.overstock.com/shoppingApi/api";char * Path = "/test/aa.htm";HINTERNET hSession = InternetOpen( "HttpSendRequestEx", INTERNET_OPEN_TYPE_PRECONFIG, 0, 0, 0);if(!hSession){printf("Failed to open session\n");exit(0);}HINTERNET hConnect = InternetConnect(hSession, Server, INTERNET_DEFAULT_HTTPS_PORT,0, 0, INTERNET_SERVICE_HTTP,0, 0);if (!hConnect)printf( "Failed to connect\n" );else{HINTERNET hRequest = HttpOpenRequest(hConnect, "POST", Path,  0, 0, 0, INTERNET_FLAG_SECURE, 0);if (!hRequest)printf( "Failed to open request handle\n" );else{if(UseHttpSendReqEx(hRequest)){printf("\nThe following was returned by the server:\n");do{dwBytesRead=0;if(InternetReadFile(hRequest, pcBuffer, BUFFSIZE-1, &dwBytesRead)){pcBuffer[dwBytesRead]=0x00; // Null-terminate bufferprintf("%s", pcBuffer);}elseprintf("\nInternetReadFile failed");}while(dwBytesRead>0);printf("\n");}if (!InternetCloseHandle(hRequest))printf( "Failed to close Request handle\n" );}if(!InternetCloseHandle(hConnect))printf("Failed to close Connect handle\n");}if( InternetCloseHandle( hSession ) == FALSE )printf( "Failed to close Session handle\n" );}BOOL UseHttpSendReqEx(HINTERNET hRequest){INTERNET_BUFFERS BufferIn;DWORD dwBytesWritten;int n;char pBuffer[1024];BOOL bRet;FILE *fp = fopen("C:/XML/xmltst.xml", "r");fgets(pBuffer, sizeof(pBuffer),fp);    // read transaction requestDWORD dwPostSize = 1024 * lstrlen(pBuffer);BufferIn.dwStructSize = sizeof( INTERNET_BUFFERS ); // Must be set or error will occur    BufferIn.Next = 0;BufferIn.lpcszHeader = 0;    BufferIn.dwHeadersLength = 0;    BufferIn.dwHeadersTotal = 0;    BufferIn.lpvBuffer = 0;BufferIn.dwBufferLength = 0;    BufferIn.dwBufferTotal = dwPostSize;BufferIn.dwOffsetLow = 0;    BufferIn.dwOffsetHigh = 0;    if(!HttpSendRequestEx( hRequest, &BufferIn, 0, 0, 0))    {   printf( "Error on HttpSendRequestEx %d\n\n",GetLastError() );   return FALSE;    }bRet=TRUE;for(n=1; n<=(int)dwPostSize/1024 && bRet; n++){if(bRet=InternetWriteFile( hRequest, pBuffer, 1024, &dwBytesWritten))printf( "\r%d bytes sent.", n*1024);} if(!bRet){   printf( "\nError on InternetWriteFile %lu\n",GetLastError() );   return FALSE;    }    if(!HttpEndRequest(hRequest, 0, 0, 0))    {   printf( "Error on HttpEndRequest %lu \n", GetLastError());   return FALSE;    }return TRUE;}   