Windows Phone 7 plurk App

Summary: Windows Phone 7 plurk App

Writing web applications with Windows Phone 7 must first study http-related operations, writing a plurk API application should be the easiest .

Of course, I have written the program of plurk API a long time ago, and the company’s webpage has been using plurk to publish new news every day, so here plurk API is not the focus, the focus is http.

The most commonly used and simple http. Everyone will think of WebClient, so open Visual Studio 2010 Express for Windows Phone and pull up the TextBox and Button , I started writing…..

WebClient client = new WebClient();

First, plurk login To use https, I’m sorry, WebClient usually adds a line first to run https

ServicePointManager.ServerCertificateValidationCallback = delegate {return true; };

Uh…how After hitting down, there is one more red line below!?!?!?
No way……… WP7 does not support https? How to log in?????
…… .
…….
After looking for a long time, I heard that??Silverlight does not support WebClient to execute https, so I started to take a sneaky step. Since https can’t be executed, then change to http….. ..

Get started now

 public partial class MainPage: PhoneApplicationPage

{
WebClient client = new WebClient();
public MainPage()
{
InitializeComponent();
client.DownloadStringCompleted += new DownloadStringCompletedEventHandler(client_DownloadStringCompleted);
client.DownloadStringAsync(new Uri("http://www.plurk.com/API/Users/login?api_key=XXX&username=YYY&password=ZZZ"));
}

void client_DownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e)
{
textBox1.Text = e.Result;
}
}

Hey~~ I saw something

Share a picture

I don’t know why HTTP works Execution, anyway, he just passed it and let me log in, so the first step was successful, and the next step is to make a puff function.

Writing here, by the way, I want to make TextBox break lines. I found inspiration here. I combined the three suggestions and wrote it down?

< b>TextWrapping=”Wrap” and ?AcceptsReturn=”True” let TextBox have Multiline mode, thank them.

Come on again, there must be cookies in the post, so I’m here? DownloadStringCompleted I wrote a handsome line before the line

string cookie = client.ResponseHeaders["Set-Cookie"].Split(';')[0];

Because this line is With many years of experience, I can intuitively react and unthinkingly, very handsome to find the previously written project and copy it easily.

But, soon, I found this line useless……

< /p>

share picture

I just add the cookie I just got before DownloadStringCompleted and give me this screen… Or22

p>

client.Headers["Cookie"] = "plurkcookiea="p/SFAL9Fy4qo7s..............";

He gave me this error: “The’Cookie’ header cannot be modified directly.rnParameter name: name”

I am very depressed. At this time, this article has been written for almost a week… ..

It seems that WebClient? 1: does not support SSL, 2: does not support Cookie, 3: does not support synchronization… What rice bowl cake… I want to give up. .. ~>”<~

It seems that there is no solution for Wp7 Exception on the Internet. I only saw that WebClient is base on XMLHttpRequest, so cookies are not supported. I’m sorry, I really don’t understand.. …

In addition to this, I also encountered Concurrent I/O operations exception

It seems that the road to developing wp7 may be quite difficult.

ok….If you don’t turn around, you can use HttpWebRequest instead Come on…

This also involves the Cross Thread problem, and it took a considerable amount of time to write the following code under the condition of sleepy eyes

 //Because nothing will be returned here, so set void

public void GetPage(String url)
{
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
request.CookieContainer = new CookieContainer();
//Global variable Cookie cookie;
if (cookie != null) request.CookieContainer.Add(new Uri(url), cookie);
request.Method = "GET";
request.BeginGetResponse(delegate(IAsyncResult ar)
{
//Get Response asynchronously
using (WebResponse response = request.EndGetResponse(ar))
{
//Global variables string status;
if (status == "login")
{
cookie = request.CookieContainer.GetCookies(request.RequestUri)["plurkcookiea"];
//Cross execution continued execution change TextBox.Text
textBox2.Dispatcher.BeginInvoke(()=>{ textBox2.Text = "welcome"; });
}
}
}, null);
}

There have been three days and three nights in this process, and many problems have been experienced…including UrlEncode problems You can use System.Uri.EscapeUriString instead.

There is still a strange problem, he said to delete? MicrosoftXDE*.dess, I don’t dare to delete it, just change the sub-file name, after rebooting!!!! !!!

Miracle!!!!!

I’m out of luck!!!!!!!

He’s puffing! !!!!!!?

share picture

?(TO EVERY LITTLE GOOD THING IN LIFE ,?………….. Cheers! )

Later, I will review the code. Actually? HttpWebRequest can also use https, just change http to https directly.

p>

Go back and look at WebClient, the same is also applicable, there is no need to worry about anything, no need to add other programs, just hit https.

share picture

This is to check whether request.RequestUri.Port runs 80 or 443 during interruption.

It’s strange to say that I changed the dess sub-file name just now, and there is nothing wrong with it. Is everything………. …

Ok! There is still a long way to go, including the use of json2XML to view and reply to friends, as well as upload photos… and other functions, I don’t have it now Let’s write down the physical strength again…. Let’s make another day!!!

Sample download:

< p>??? ?? share picture

ps1: plurk’s api_key needs to be applied for by yourself

ps2: Or22 is the 3D version of OTZ< /p>

ps3: WindowsPhoneApplication7.zip is really Version 7

ps4: The above may not apply after 2010/9/16

Original text: Big column Windows Phone 7 plurk App

Leave a Comment

Your email address will not be published.