Click here to Skip to main content
15,888,113 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi i am building a simple c++ program using http/https proxy. I tried it to use the MFC CInternetSession class. But it didn't work over many proxy servers. So I tried it to use the libcurl. It seems that working well. But I am tired. When i try to post the form to website. I saw the somethings as follows in smart sniffer.

[2016-01-13 1:49:16:973]
CONNECT m.pmang.com:443 HTTP/1.1
User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; .NET CLR 2.0.50727; .NET CLR 1.1.4322)
Host: m.pmang.com
Proxy-Connection: Keep-Alive

[2016-01-13 1:49:17:285]
HTTP/1.1 200 Connection established

[2016-01-13 1:49:17:300]
00000000 16 03 01 00 EA 01 00 00 E6 03 01 40 D2 75 C5 FF ........ ...@.u..

My Code also received the "HTTP/1.1 200 Connection established" What is it? What should i do for fix it? Where is Http/Https proxy library working on general proxy servers(50.195.87.31:3128)?

I posted the form content. so I have to receive response html from remote server. for example <html> XXX </html>. But my code receive the "HTTP/1.1 200 Connection established" from proxy server.

I am now using libcurl For example How should i write the code with libcurl?
Posted

CURLOPT_WRITEFUNCTION is your friend. The function you give libcurl when you set this option is called whenever you get a response from the server after performing the operation.
 
Share this answer
 
"HTTP/1.1 200 Connection established" is the initial response line (status line) from the server to your request. Depending on the request it is followed by the header lines and the message body (which you are interested in). You may parse these information to know if the connection was successful and also parse the header line to know about body encoding.

You may have a look at this link: HTTP Made Really Easy[^].

With libcurl, you can use the CURLOPT_WRITEFUNCTION[^] to write the body data to a buffer or file (see also the example at the end of the above link).
 
Share this answer
 
Comments
saifmossel 13-Jan-16 11:58am    
Hi I wrote as follows for post param.
formData = m_curl.BuildForm(_T("bscreenview"), _T(""),
_T("bscreenssn"), _T(""),
_T("bscreenbserial"), _T(""),
_T("bscreendomain"), _T(""),
_T("bscreenano"), _T(""),
_T("bscreentype"), _T(""),
_T("hashparams"), _T("pmangHome"),
_T("return_url"), _T(""),
_T("sns"), _T(""),
_T("provider_access_token"), _T(""),
_T("provider_refresh_token"), _T(""),
_T("path"), _T(""),
_T("offline"), _T(""),
_T("provider"), _T(""),
NULL);

//formData.Empty();
if (!m_curl.Post(_T("https://secure.m.pmang.com/?view=login_prc"), formData, m_resultHeader, m_resultString))
return 0;

and I defined to my curl wrapper class for get the received header/data.


size_t CCurl::header_callback(char *buffer, size_t size,
size_t nitems, void *userdata)
{
/* received header is nitems * size long in 'buffer' NOT ZERO TERMINATED */
/* 'userdata' is set with CURLOPT_HEADERDATA */
CString *header = (CString*)userdata;
CStringA tempheaderA;
CString tempheader;

tempheaderA = buffer;

tempHeader = tempheaderA;


header.Append(tempheader);

return nitems * size;
}

size_t CCurl::body_callback(char *buffer, size_t size,
size_t nitems, void *userdata)
{
/* received header is nitems * size long in 'buffer' NOT ZERO TERMINATED */
/* 'userdata' is set with CURLOPT_HEADERDATA */
//CStringA *body = (CStringA*)userdata;

CString *body = (CString*)userdata;
CStringA tempbodyA;
CString tempbody;

tempbodyA = buffer;

tempbody = tempbodyA;


body.Append(tempbody);

return nitems * size;
}

It is proxy setting code:

CStringA proxyIp = m_proxyAddrA.Mid(0, off);
curl_easy_setopt(curl, CURLOPT_PROXY, proxyIp.GetString());
int port = atoi(m_proxyAddrA.Mid(off + 1, m_proxyAddrA.GetLength() - off - 1).GetString());
curl_easy_setopt(curl, CURLOPT_PROXYPORT, port);



Without proxy It receive the header/format perfectly.
It look like I don't know about using proxy with libcurl.
How should i use proxy with libcurl?
Jochen Arndt 13-Jan-16 12:10pm    
Read 'Proxies' at http://curl.haxx.se/libcurl/c/libcurl-tutorial.html.

Check your proxy string and what is happening (any errors returned by libcurl).

Check if the used proxy is a HTTP proxy. If not you must inform libcurl about the proxy type.

Note also that you don't need to specify proxy address and port separately when passing address:port.
Hi I wrote as follows for post param.

C++
            formData = m_curl.BuildForm(_T("bscreenview"), _T(""),
			_T("bscreenssn"), _T(""),
			_T("bscreenbserial"), _T(""),
			_T("bscreendomain"), _T(""),
			_T("bscreenano"), _T(""),
			_T("bscreentype"), _T(""),
			_T("hashparams"), _T("pmangHome"),
			_T("return_url"), _T(""),
			_T("sns"), _T(""),
			_T("provider_access_token"), _T(""),
			_T("provider_refresh_token"), _T(""),
			_T("path"), _T(""),
			_T("offline"), _T(""),
			_T("provider"), _T(""),
			NULL);

		//formData.Empty();
		if (!m_curl.Post(_T("https://secure.m.pmang.com/?view=login_prc"), formData, m_resultHeader, m_resultString))
			return 0;

and I defined to my curl wrapper class for get the received header/data. 


size_t CCurl::header_callback(char *buffer, size_t size,
	size_t nitems, void *userdata)
{
	/* received header is nitems * size long in 'buffer' NOT ZERO TERMINATED */
	/* 'userdata' is set with CURLOPT_HEADERDATA */
	CString *header = (CString*)userdata;
	CStringA tempheaderA;
	CString tempheader;

	tempheaderA = buffer;

	tempHeader = tempheaderA;


	header.Append(tempheader);

	return nitems * size;
}

size_t CCurl::body_callback(char *buffer, size_t size,
	size_t nitems, void *userdata)
{
	/* received header is nitems * size long in 'buffer' NOT ZERO TERMINATED */
	/* 'userdata' is set with CURLOPT_HEADERDATA */
	//CStringA *body = (CStringA*)userdata;
	
	CString *body = (CString*)userdata;
	CStringA tempbodyA;
	CString tempbody;

	tempbodyA = buffer;

	tempbody = tempbodyA;


	body.Append(tempbody);

	return nitems * size;
}


It is proxy setting code:
C++
CStringA proxyIp = m_proxyAddrA.Mid(0, off);
			curl_easy_setopt(curl, CURLOPT_PROXY, proxyIp.GetString());
			int port = atoi(m_proxyAddrA.Mid(off + 1, m_proxyAddrA.GetLength() - off - 1).GetString());
			curl_easy_setopt(curl, CURLOPT_PROXYPORT, port);


Without proxy It receive the header/format perfectly.
It look like I don't know about using proxy with libcurl.
How should i use proxy with libcurl?
 
Share this answer
 
v3

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900