Using system;
Using system. Collections. Generic;
Using system. LINQ;
Using system. net;
Using system. windows;
Using system. Windows. controls;
Using system. Windows. documents;
Using system. Windows. input;
Using system. Windows. Media;
Using system. Windows. Media. animation;
Using system. Windows. shapes;
Using Microsoft. Phone. controls;
Using Microsoft. Internal;
Using system. xml;
Using system. IO;
Using system. text;
Using system. Threading;
Using system. net. browser;
Namespace panoramaapp2
{
Public partial class mainpage: phoneapplicationpage
{
Private Static string pmessage;
Public static manualresetevent alldone = new manualresetevent (false );
Public httpwebrequest objrequest = NULL;
Public static string myrequestdata = string. empty;
Public String urladdress = "http: // web address/client/login? Account = 1 & Password = 2 & phonetype = 3 & devicetoken = 1 ";
Public mainpage ()
{
Initializecomponent ();
// Set the data context of The ListBox control to the sample data
Datacontext = app. viewmodel;
This. Loaded + = new routedeventhandler (mainpage_loaded );
Dosend ();
}
Public void dosend ()
{
Stringbuilder completeurl = new stringbuilder (urladdress );
Objrequest = (httpwebrequest) webrequest. Create (urladdress. tostring ());
Objrequest. contenttype = "application/X-WWW-form-urlencoded ";
Objrequest. method = "Post ";
// Adding Headers
Objrequest. headers ["Header"] = "your value ";
Objrequest. headers ["content-language"] = "En-us ";
Myrequestdata = "your request data ";
// Begins the asynchronous request
Objrequest. begingetrequeststream (New asynccallback (getrequeststreamcallback), objrequest );
}
Private Static void getrequeststreamcallback (iasyncresult asyncresult)
{
Httpwebrequest objhttpwebrequest = (httpwebrequest) asyncresult. asyncstate;
// End the operation
Stream poststream = objhttpwebrequest. endgetrequeststream (asyncresult );
// Convert the string into a byte array.
Byte [] bytearray = encoding. utf8.getbytes (myrequestdata );
// Write to the request stream.
Poststream. Write (bytearray, 0, myrequestdata. Length );
Poststream. Close ();
// Start the asynchronous operation to get the response
Objhttpwebrequest. begingetresponse (New asynccallback (getresponsecallback), objhttpwebrequest );
// Request. begingetresponse (New asynccallback (getresponsecallback), objhttpwebrequest );
}
Private Static void getresponsecallback (iasyncresult asyncresult)
{
Httpwebrequest objhttpwebrequest = (httpwebrequest) asyncresult. asyncstate;
Httpwebresponse objhttpwebresponse = (httpwebresponse) objhttpwebrequest. endgetresponse (asyncresult );
Stream objstreamresponse = objhttpwebresponse. getresponsestream ();
Streamreader objstreamreader = new streamreader (objstreamresponse );
String responsestring = objstreamreader. readtoend (); // got response here
// MessageBox. Show ("response:" + responsestring );
// Close the Stream Object
Objstreamresponse. Close ();
Objstreamreader. Close ();
Objhttpwebresponse. Close ();
}
}
}