0

How can get php session values or how can i set cookies from c# app itself?

currently i can successfully get/post data but i need cookie support in weclient?

my code

        App.webClient.UploadStringAsync(uri, "POST", datax);
user3529738
  • 83
  • 1
  • 9

1 Answers1

0

I do not see the the exact use case you are working on, but as you are working with cookies, I recommend you start using HttpWebRequest over WebClient. This class provides you with a CookieContainer.

The Cookies Property of HttpWebRequest would help you to send a Cookie from your client to the server, where the HttpWebResponse.Cookies Property get you the possibility to read the cookie, sent by the server.

See Using CookieContainer with WebClient class on how to override your WebClient to gain the ability of using the CookieContainer provided by the HttpWebRequest.

A brief WebClient vs HttpWebRequest can be found on CodeProject

Community
  • 1
  • 1
flo scheiwiller
  • 2,706
  • 2
  • 17
  • 15
  • can i get a php session variable so server side session or client side? – user3529738 Apr 18 '14 at 20:38
  • WebClient wb = new WebClient(); wb.Headers.Add(HttpRequestHeader.Cookie, "somecookie"); System.Net.WebHheaderCollection does not contain a definition for Add .... i got this error – user3529738 Apr 18 '14 at 21:26
  • yes. this is why I advised you to use HttpWebRequest over WebClient. See http://msdn.microsoft.com/de-de/library/system.net.httpwebrequest.cookiecontainer(v=vs.110).aspx for another sample. (as well as supporting frameworks) – flo scheiwiller Apr 18 '14 at 21:31
  • HttpWebRequest myReq = (HttpWebRequest)WebRequest.Create("http://.co/login.php"); myReq.Method = "POST"; myReq.ContentType = "application/json"; Stream dataStream = myReq.GetRequestStream(); i am getting getrequeststrem not found, i am using system.io and system.net whats wrong – user3529738 Apr 19 '14 at 09:00
  • see msdn for a sample on how to use httpWebRequest with the cookieContainer. http://msdn.microsoft.com/en-us/library/windowsphone/develop/dd920298(v=vs.105).aspx – flo scheiwiller Apr 19 '14 at 12:24