using wininet api to connect to web service on https
i have web service written in C#.net 2.0 framework and i am trying to assist someone that is using the wininet api to connect and send soap request to it. dont think i am configuring the httpsSession correctly. always get a http error 400 bad syntax back from the server after sending request
the excerpt from example app written on vc++6 that i am working with is below to connet
char* agent = "MyWebServiceTest";
unsigned int accessType = INTERNET_OPEN_TYPE_DIRECT;
char* proxyName = NULL;
char* proxyByPass = NULL;
unsigned long connectionFlag = 0;
//baseSession variables
char* serverName = "secure.site.state.ar";
INTERNET_PORT serverPort = 8443;
char* userName = NULL;
char* passWord = NULL;
unsigned long serviceType = INTERNET_SERVICE_HTTP; //handles http and https
unsigned long baseSessionFlags = 0;
unsigned long baseSessionContext = 12345; //Application-defined; identifies the appication context for the returned handle in callbacks
//httpsSession variables
char* httpType = "PUT";
char* requestedResource = "Service1.asmx";
char* httpVersion = "HTTP/1.1";
char* referer = NULL;
char** acceptedTypes = new char*("text/xml; charset=utf-8","\0");
unsigned int httpSessionFlags = INTERNET_FLAG_SECURE;
unsigned int httpSessionContext = 12345;
HINTERNET connection = InternetOpen( agent, accessType, proxyName, proxyByPass, connectionFlag );
HINTERNET baseSession = InternetConnect( connection, serverName, serverPort, userName, passWord, serviceType, baseSessionFlags, baseSessionContext);
HINTERNET httpsSession = HttpOpenRequest( baseSession, httpType, requestedResource, httpVersion, referer, (const char**)acceptedTypes, httpSessionFlags, httpSessionContext);
string header1 = "Content-Type: text/xml;charset=utf-8\r\n";
string header2 = "Content-Length: ";
string header3 = "SOAPAction: "https://secure.site.state.ar/Service1Ping"
(header2 += itoa(soap0.length(), new char[soap0.length()], 10)) += "\r\n";
header1 += header2;
if( HttpAddRequestHeaders(httpSession,header1.c_str(), header1.length(),HTTP_ADDREQ_FLAG_COALESCE_WITH_CO MMA) == 0 )
cout<<"Error adding headers error code "<<GetLastError();
if( HttpSendRequest(httpSession, NULL,0, (void*)soap.c_str(), soap.length()) != 0 )
{
/// response reading stuff here
}
__________________
Mike
Last edited by C@uark; September 24th, 2009 at 02:51 PM..
|