add header using c++

Add-in Express™ Support Service
That's what is more important than anything else

add header using c++
 
pa1 modi


Guest


hi sergey,

hey may i have code for add new header on particular request using c++..??

if you have sample code for add header in web request then plz provide..

thanks,
Posted 19 Sep, 2011 00:26:51 Top
pa1 modi


Guest


hi sergey,

i have use following code for add header on particular http webrequest. but i cant get that header which i set by request->Headers->Add("MyCustomHeaderValue", "test");

i want that header in response..how can i get custom request header in response..??


private: System::Void IEModule_BeforeNavigate2(AddinExpress::IE::ADXIEBeforeNavigate2EventArgs^ e)
{

MessageBox::Show("before navigate");

HttpWebRequest^ request = (HttpWebRequest^)( WebRequest::Create( "http://www.google.com" ) );

request->Method = "GET";
request->Headers->Add("MyCustomHeaderValue", "test");

HttpWebResponse^ response =dynamic_cast<HttpWebResponse^>(request->GetResponse());

MessageBox::Show("Request header count: {0}"+response->Headers->Count);

WebHeaderCollection^ header = response->Headers;
for (int i = 0; i < header->Count; i++)
{
MessageBox::Show("{0}"+header->GetKey(i)+"{1}"+header[i]);
}

response->Close();

}
Posted 19 Sep, 2011 03:18:15 Top
Sergey Grischenko


Add-in Express team


Posts: 7233
Joined: 2004-07-05
Hi Pavan,

Did you develop an ASP.NET application that processes the request on the server-side?
Posted 19 Sep, 2011 05:35:41 Top
pa1 modi


Guest


yes sergey, i'm developing ASP.NET application which processes the request server side..

and how can i get this 'request->Headers->Add("MyCustomHeaderValue", "test");' custom header in
http response header using c++ code??
Posted 19 Sep, 2011 05:41:56 Top
Sergey Grischenko


Add-in Express team


Posts: 7233
Joined: 2004-07-05
The example code of ASP.NET application was published here:
http://www.add-in-express.com/forum/read.php?PAGEN_1=2&FID=10&TID=9744#nav_start
Posted 19 Sep, 2011 05:50:00 Top
pa1 modi


Guest


can u provide this code me in c++?

object dummy = null;
object url = "http://localhost:51145/default.aspx";;
object header = "MyCustomHeaderValue:test\r\n";
this.IEApp.Navigate2(ref url, ref dummy, ref dummy, ref dummy, ref header);
Posted 19 Sep, 2011 06:19:28 Top
pa1 modi


Guest


hi sergey,

i have already check this code which is on this link in c# but it's dont get headers in response.

http://www.add-in-express.com/forum/read.php?PAGEN_1=2&FID=10&TID=9744#nav_start


i want that header which i set using 'request->Headers->Add("MyCustomHeaderValue", "test");'
in 'response->Headers' using c++..

plz provide c++ code for same..
Posted 20 Sep, 2011 04:11:42 Top
Sergey Grischenko


Add-in Express team


Posts: 7233
Joined: 2004-07-05
Hi Pavan,

To get the header in your code you need to add the header using this.Response.AddHeader method of the Response object available on ASP.NET web pages.
The code mentioned above was tested by me. It worked fine.
Pavan, we don't provide the support for ASP.NET. Please ask the questions regarding ASP.NET on corresponding forums.
Posted 20 Sep, 2011 05:09:26 Top
pa1 modi


Guest


ya sergey,

i have already add headers using following code:

shellWindows = gcnew Interop::SHDocVw::ShellWindowsClass();

for each (Interop::SHDocVw::InternetExplorer ^ ie in shellWindows )
{
url=ie->LocationURL;
}

MessageBox::Show("before navigate");

request = (HttpWebRequest^)( WebRequest::Create(url) );

request->Method = "post";
request->Headers->Add("MyCustomHeaderValue", "test");

response =dynamic_cast<HttpWebResponse^>(request->GetResponse());

//String ^ value = response->Headers["MyResponseHeaderValue"];
//if (!String::IsNullOrEmpty(value))
//{
//if (value->Equals("Request processed successfully."))
//MessageBox::Show(this, value);
//}

MessageBox::Show("Request header count: {0}"+response->Headers->Count);

WebHeaderCollection^ header = response->Headers;
for (int i = 0; i < header->Count; i++)
{
MessageBox::Show("{0}"+header->GetKey(i)+"{1}"+header[i]);
}

response->Close();



but still dont get added header in response..
Posted 20 Sep, 2011 06:02:25 Top
Sergey Grischenko


Add-in Express team


Posts: 7233
Joined: 2004-07-05
No, the code above doesn't add the headder. It just send it to the server. In its turn, the server should process your request (with the header) and add the new header again so that you can get it in the Response object of your add-on.
Posted 20 Sep, 2011 06:28:00 Top