I found converted code for xaml as below (both code purpose are same but syntax different):
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 System.IO;
using System.Text;
namespace TestApp
{
public partial class googlefusion : PhoneApplicationPage
{
string email = "punit.belani@gmail.com";
string password = "punit1234";
string token = "";
public delegate void updatetextdelegate(string text);
public googlefusion()
{
InitializeComponent();
}
private void searchOnlineRequest(IAsyncResult asyncResult)
{
string sdata =
"accountType=" + HttpUtility.UrlEncode("HOSTED_OR_GOOGLE") + "&"
+ "Email=" + HttpUtility.UrlEncode(email) + "&"
+ "Passwd=" + HttpUtility.UrlEncode(password) + "&"
+ "service=" + HttpUtility.UrlEncode("fusiontables") + "&"
+ "source=" + HttpUtility.UrlEncode("fusiontables.ApiExample")
+ "&logintoken=&logincaptcha=";
UTF8Encoding encoding = new UTF8Encoding();
HttpWebRequest request = (HttpWebRequest)asyncResult.AsyncState;
Stream _body = request.EndGetRequestStream(asyncResult);
byte[] formBytes = encoding.GetBytes(sdata);
_body.Write(formBytes, 0, formBytes.Length);
_body.Close();
request.BeginGetResponse(SearchResponseCallback, request);
}
private void SearchResponseCallback(IAsyncResult asyncResult)
{
HttpWebRequest request = (HttpWebRequest)asyncResult.AsyncState;
HttpWebResponse response = (HttpWebResponse)request.EndGetResponse(asyncResult);
Stream content = response.GetResponseStream();
if (request != null && response != null)
{
if (response.StatusCode == HttpStatusCode.OK)
{
using (StreamReader reader = new StreamReader(content))
{
string _responseString = reader.ReadToEnd();
char[] delim = new char[] { '=' };
string[] parts = _responseString.Split(delim);
token = parts[3];
reader.Close();
}
}
}
HttpWebRequest requestOut = HttpWebRequest.CreateHttp("http://tables.googlelabs.com/api/query?sql=select * from 3354083");
requestOut.Headers["Authorization"] = "GoogleLogin auth=" + token;
requestOut.ContentType = "application/x-www-form-urlencoded";
requestOut.Method = "POST";
requestOut.BeginGetRequestStream(searchOnlineRequestOut, requestOut);
}
private void searchOnlineRequestOut(IAsyncResult asyncResult)
{
UTF8Encoding encoding = new UTF8Encoding();
HttpWebRequest request = (HttpWebRequest)asyncResult.AsyncState;
request.BeginGetResponse(SearchResponseCallbackOut, request);
}
private void SearchResponseCallbackOut(IAsyncResult asyncResult)
{
HttpWebRequest request = (HttpWebRequest)asyncResult.AsyncState;
HttpWebResponse response = (HttpWebResponse)request.EndGetResponse(asyncResult);
Stream content = response.GetResponseStream();
if (request != null && response != null)
{
if (response.StatusCode == HttpStatusCode.OK)
{
using (StreamReader reader = new StreamReader(content))
{
string _responseString = reader.ReadToEnd();
this.Dispatcher.BeginInvoke(new updatetextdelegate(Updatetext), _responseString);
reader.Close();
}
}
}
}
private void Updatetext(string text)
{
lblOut.Text = text;
}
private void PhoneApplicationPage_Loaded(object sender, RoutedEventArgs e)
{
HttpWebRequest request = HttpWebRequest.CreateHttp("https://www.google.com/accounts/ClientLogin");
request.ContentType = "application/x-www-form-urlencoded";
request.Method = "POST";
request.BeginGetRequestStream(searchOnlineRequest, request);
}
}
}