Pocket PC Networking >> what's wrong with this function?about "WebResponse()" in C#

by Choice » Tue, 29 Nov 2005 01:19:48 GMT

this function will post some data to the server, and then the server will
send back some message,
it is works in either winform or webform programs,but not in smart device
programs. what's the problem?

public int GetResponse(ref string OutPut)
{
int iResult = 0;
string SendContain = "";

//Init HttpWebRequest
System.Net.HttpWebRequest myRequest =
(HttpWebRequest)WebRequest.Create(_RequestUrl); // _RequestUrl : post
url
myRequest.ContentType = "application/x-www-form-urlencoded";
myRequest.Timeout = 10000;
myRequest.Method = "POST";

//build the content what will be sent
for(int i = 0 ; i<_Item.Count;i++)
{
if(SendContain!="")
SendContain += "&";
SendContain += _Item.GetKey(i) + "=" + _Item[i];
}

//input the string into byte[]
byte []PostData = System.Text.Encoding.Default.GetBytes(SendContain);
myRequest.ContentLength = PostData.Length;

//send the data
try
{
myRequest.KeepAlive = true;
System.IO.Stream PostBuffer = myRequest.GetRequestStream();
System.IO.Stream ReceiveBuffer;
System.IO.StreamReader sr;
PostBuffer.Write(PostData,0,PostData.Length);
ReceiveBuffer = myRequest.GetResponse().GetResponseStream(); //here will
raise a error
sr= new StreamReader(ReceiveBuffer,Encoding.Default);
OutPut = sr.ReadToEnd();
}
catch(System.Exception ee)
{
OutPut = ee.Message;
return -6; //cannot connect with server
}
return iResult;
}

thanks




Similar Threads

1. what's wrong with this function?about "WebResponse()" in C#

this function will post some data to the server, and then the server will
send back some message,
it is works in either winform or webform programs,but not in smart device
programs. what's the problem?

public int GetResponse(ref string OutPut)
  {
   int iResult = 0;
   string SendContain = "";

   //Init HttpWebRequest
   System.Net.HttpWebRequest myRequest =
    (HttpWebRequest)WebRequest.Create(_RequestUrl); // _RequestUrl : post
url
   myRequest.ContentType = "application/x-www-form-urlencoded";
   myRequest.Timeout = 10000;
   myRequest.Method = "POST";

   //build the content what will be sent
   for(int i = 0 ; i<_Item.Count;i++)
   {
    if(SendContain!="")
     SendContain += "&";
    SendContain += _Item.GetKey(i) + "=" + _Item[i];
   }

   //input the string into byte[]
   byte []PostData = System.Text.Encoding.Default.GetBytes(SendContain);
   myRequest.ContentLength = PostData.Length;

   //send the data
   try
   {
    myRequest.KeepAlive = true;
    System.IO.Stream PostBuffer = myRequest.GetRequestStream();
    System.IO.Stream ReceiveBuffer;
    System.IO.StreamReader sr;
    PostBuffer.Write(PostData,0,PostData.Length);
    ReceiveBuffer = myRequest.GetResponse().GetResponseStream(); //here will
raise a error
    sr= new StreamReader(ReceiveBuffer,Encoding.Default);
    OutPut = sr.ReadToEnd();
   }
   catch(System.Exception ee)
   {
    OutPut = ee.Message;
    return -6; //cannot connect with server
   }
   return iResult;
  }

thanks



2. What's wrong with the accept function ?

3. What's wrong?

Hi Guys,

My 9 months old iPaq 1935 ran perfectly until yesterday before refusing to
start. The last thing he did was to respond to the alarm i set and died.
I thought it ran out of power and i recharged for awhile and tried starting
but nothing seems to happen. I just have to stare at a blank screen.

Any idea what could have gone wrong ? Battery ?? switch ? etc.

Thanks much for any inputs

Happy New Year!
aegee


4. What's wrong with timeSetEvent() - Pocketpc Developer

5. what's wrong with message threading in 6.1

I cannot read Inbox messages (SMS) since WM6.1. start to use so called 
mesagess threading.
what's wrong?!

the below codes work very well when I turn off "messages threading"
but with this feature it retuns nothing. no messages.


....
   SizedSPropTagArray(3, rgTags) = 
{3,{PR_CE_IPM_INBOX_ENTRYID,PR_OBJECT_TYPE,PR_SUBFOLDERS}};
   hr = pPop3Store->GetProps((LPSPropTagArray)&rgTags, MAPI_UNICODE, 
&cValues, &rgprops);


   IMAPIFolder *pPOPInboxFolder = NULL;
   hr = pPop3Store->OpenEntry(rgprops[0].Value.bin.cb, 
(LPENTRYID)rgprops[0].Value.bin.lpb, NULL, MAPI_MODIFY, NULL, 
(LPUNKNOWN*)&pPOPInboxFolder);

   IMAPITable *pIInboxTable = NULL;
   hr = pPOPInboxFolder->GetContentsTable(0, &pIInboxTable);


   SizedSPropTagArray(6, tblMessages) = {5,{ PR_MESSAGE_DELIVERY_TIME,\
              PR_SENDER_NAME,\
              PR_SENDER_EMAIL_ADDRESS,\
              PR_SUBJECT, \
              PR_MESSAGE_FLAGS}};
   hr = pIInboxTable->SetColumns((LPSPropTagArray)&tblMessages, 0);
   hr = pIInboxTable->Restrict(NULL, 0);

   SizedSSortOrderSet(4, sosm) = {1,0,0,{PR_MESSAGE_DELIVERY_TIME, 
TABLE_SORT_DESCEND}};

   while(1)
{
    SRowSet *iRowSet = NULL;

    hr = pIInboxTable->QueryRows(1, 0, &iRowSet);

    if (iRowSet->cRows != 1)
    {
     FreeProws(iRowSet);
     iRowSet = NULL;

     break;
    }

    if (iRowSet->aRow[0].lpProps[0].ulPropTag==PR_MESSAGE_DELIVERY_TIME)
    {
....




6. What's wrong with this code? - Pocketpc Developer

7. what's wrong with my setting?

HP 4700 with either CF or SD card.
4700 can play whatever wmv files I saved on the 4GB SD card but refused to 
save wmv files through the pocket PC IE. It keeps complaining "not enough 
space" even though I have 512 or close to 1.8GB of space left.
I think it goes back to "Main memory" even though I specifically change save 
location to SD/CF...

What is wrong? 


8. API PlaySound function playing wrong sound - Pocketpc Developer