2009年9月28日 星期一

Google Calendar Api query constrain

在使用google calendar api 中, 其實有以個預設的查詢限制,

舉例來說,若想要查詢其中一本日曆的事件, 但一次查最多只有25筆
如 : http://www.google.com/calendar/feeds/default/private/full
解果只會傳回最新的25筆資料


但 若要查詢所有的資料的話,可以設定 max-results 的數量, 將他設定一個很大的值
如,可以將url 改為
http://www.google.com/calendar/feeds/default/private/full?max-results=200



見 google 常見問題 How do I retrieve more than 25 results in an event feed?

Google Calendar api in javascript

之前將 google calendar 試過了 .net 和 java 上應用, 現在來試試 javascript 。

在是的過程中發現了幾項限制

1. 必須要架在server 上
可以用 apache 或 iis 的方法, 我這裡是用 eclipse + google app engine 的方式 ,之後在上傳到 google app engine 上

2. 在網頁上要至少放一個圖檔
這個限制有點奇怪,不過不放的話會有一個 「An image of the same domain is required on this page for authenticated reads and all writes.」的錯誤 (參考 Geoffrey's 有人QWERTY絮語 )

之後照者 Google Calendar APIs and Tools 的教學即可

以下是我寫得 範例

2009年9月17日 星期四

Upload image to the picasa web album

在 C# 要使用 picasa web album data api , 在下在完 google api 後, 記得 include 以下的 dll

  • Google Data API Access Control Library
  • Google Data API Core Library
  • Google Data API Extansions Library
  • Google Data API Picasa Library

這個範例輸入 以下資訊就可以上傳 圖片到picasa,不同於google 官方範例是從檔案路徑讀取檔案在上傳 ,這裡 傳入一個 BitmapImage 即可取得 圖片的資料


註 1、 Image Type
  • image/bmp
  • image/gif
  • image/jpeg
  • image/png
註 2、 Picasa Web Albums Data API - C# delelper's guide

Code 如下





/**
* @Name UpLoadImageToWebAlbum
*
* Upload photo to the the picasa web album,
* In there, using the StreamSource get the photo byte array
*
* @param Account [in] - the google accpount
* @param Password [in] - the google accpount's password
* @param AlbumUri [in] - the google picasa web album uri
* @param PhotoID [in] - the photo id
* @param Image [in] - the image which want upload
*
*/
public void UpLoadImageToWebAlbum(string Account, string Password, string AlbumUri, String PhotoID, BitmapImage Image)
{


/// Set Service
PicasaService service = new PicasaService("UploadImag");

/// Set Account and Password
service.setUserCredentials(Account, Password);


/// Set Uri
Uri postUri = new Uri(AlbumUri);


/// Set proxy
GDataRequestFactory requestFactory = (GDataRequestFactory)service.RequestFactory;
IWebProxy iProxy = WebRequest.DefaultWebProxy;
WebProxy myProxy = new WebProxy(iProxy.GetProxy(postUri));

///potentially, setup credentials on the proxy here
myProxy.Credentials = CredentialCache.DefaultCredentials;

myProxy.UseDefaultCredentials = true;
requestFactory.Proxy = myProxy;


/// Insert photo
/// service.Insert(the album uri, image's StreamSource, image type , the image name );
service.Insert(postUri, Image.StreamSource, "image/png", "" + PhotoID);

///Insert Pic

/// Close stream
Image.StreamSource.Close();

MessageBox.Show("OK");



}



Get picasa web album Photo list in album by c#

在 C# 要使用 picasa web album data api , 在下在完 google api 後, 記得 include 以下的 dll

  • Google Data API Access Control Library
  • Google Data API Core Library
  • Google Data API Extansions Library
  • Google Data API Picasa Library



這個範例輸入 帳號、密碼及 AlbumUri 就可以取得 在這個相簿裡的 所有的photo 資料

註1、 AlbumUri 可以見上一篇 取得的 FeedUri
註2、 entry.Content.AbsoluteUri 就是實際存放相片的位址




/**
* @Name GetPhotoListInAlbum
*
* Get album list from the picasa web album
*
* @param Account [in] - the google accpount
* @param Password [in] - the google accpount's password
* @param AlbumUri [in] - the google picasa web album uri
*
*/
public void GetPhotoListInAlbum(string Account, string Password, string AlbumUri)
{


/// Set Service
PicasaService service = new PicasaService("Get_Album_List");

/// Set Account and Password
service.setUserCredentials(Account, Password);

/// Set Query
PhotoQuery query = new PhotoQuery(AlbumUri);


/// Set proxy
GDataRequestFactory requestFactory = (GDataRequestFactory)service.RequestFactory;

IWebProxy iProxy = WebRequest.DefaultWebProxy;

WebProxy myProxy = new WebProxy(iProxy.GetProxy(query.Uri));

///potentially, setup credentials on the proxy here
myProxy.Credentials = CredentialCache.DefaultCredentials;
myProxy.UseDefaultCredentials = true;
requestFactory.Proxy = myProxy;


/// Get feed
PicasaFeed feed = service.Query(query);


/// Get Album count
int count = feed.Entries.Count;
Console.WriteLine(count);


foreach (PicasaEntry entry in feed.Entries)
{
/// Get album title
string title = entry.Title.Text;
Console.WriteLine(title);

/// Get the image uri
string uri = entry.Content.AbsoluteUri;
Console.WriteLine(uri);
}

}



Get picasa web album list by c#

在 C# 要使用 picasa web album data api , 在下在完 google api 後, 記得 include 以下的 dll

  • Google Data API Access Control Library
  • Google Data API Core Library
  • Google Data API Extansions Library
  • Google Data API Picasa Library
下面這個 例子 就是 輸入 google 帳號和密碼後就可以取得所有的相簿清單

註1 、 其中要注意的就是 query 的用法, 預設 可以使用 "default" 來取得自己的相簿清單
但是可以取代成其他使用者,用這語法來找到你想知道的人的相簿(僅限於他公開或分享給你的)


例如 朋友的帳號為 xxxxx@gmail.com
FriendAccountName = "xxxxx";

語法可以 轉成
AlbumQuery query = new AlbumQuery(PicasaQuery.CreatePicasaUri(FriendAccountName));


註2 、 取得後 entry.FeedUri 可以取得 相簿的 uri 位址, 可利用這個位址取得在這相簿所有的圖片資訊

code 如下




/**
* @Name GetAlbumList
*
* Get album list from the picasa web album
*
* @param Account [in] - the google accpount
* @param Password [in] - the google accpount's password
*
*
*/
public void GetAlbumList(string Account, string Password)
{


/// Set Service
PicasaService service = new PicasaService("Get_Album_List");

/// Set Account and Password
service.setUserCredentials(Account, Password);

/// Set Query , default is the account user,
/// "default" can chang other user name to get other album (if that user set public or share with you)
AlbumQuery query = new AlbumQuery(PicasaQuery.CreatePicasaUri("default"));


/// Set proxy
GDataRequestFactory requestFactory = (GDataRequestFactory)service.RequestFactory;

IWebProxy iProxy = WebRequest.DefaultWebProxy;

WebProxy myProxy = new WebProxy(iProxy.GetProxy(query.Uri));

// /potentially, setup credentials on the proxy here
myProxy.Credentials = CredentialCache.DefaultCredentials;
myProxy.UseDefaultCredentials = true;
requestFactory.Proxy = myProxy;


/// Get feed
PicasaFeed feed = service.Query(query);


/// Get Album count
int count = feed.Entries.Count;
Console.WriteLine(count);


foreach (PicasaEntry entry in feed.Entries)
{
/// Get album title
string title = entry.Title.Text;
Console.WriteLine(title);

/// Get Album feed uri , by this uri can get the photo information in this album
string Uri = entry.FeedUri;
Console.WriteLine(Uri);

}

}



2009年9月16日 星期三

圖片存取 in sqlite by C# 2

之前有寫過

圖片存取 in sqlite by C#


這一篇,但那一篇的作法試從檔案中讀取圖片資料在存入sqlite的資料庫中的;

不同於那篇文章, 現在修改了一部分,能夠讀取畫面中的圖像的byte array
(在此是用C# WPF的語法)

GetImageSourceByte function 說明︰
傳入一個 ImageSource ,利用 PngBitmapEncoder 的方式將ImageSource 轉成一個 Stream 並存入 MemoryStream 中; 最後在從 MemoryStream 取得資料存到 byte array中,

參考 定義




/**
* @Name GetImageSourceByte
*
* Get the ImageSource Byte array, which can save in database as BLOB type
*
* @param EventImage [in] - image to save
* @return the image byte array
*
*/
public byte[] GetImageSourceByte(ImageSource EventImage)
{
byte[] MyData = null;

/// new a JpegBitmapEncoder and add r into it
PngBitmapEncoder e = new PngBitmapEncoder();
e.Frames.Add(EventImage as BitmapFrame);

/// new memoryStream
MemoryStream ms = new MemoryStream();

/// Save to memory
e.Save(ms);

/// Re set the position, or read the memory from the last position
///ms.Seek(0, SeekOrigin.Begin);
/// Or set position
ms.Position = 0;

MyData = new byte[ms.Length];
ms.Read(MyData, 0, System.Convert.ToInt32(ms.Length));

ms.Close();

return MyData;

}




這裡說明一下 如何取得 傳入要傳的 ImageSource
參考 定義



/// Get bound of the visual
/// g is the WPF visual object, such as "grid","canvas", "Image", ...
Rect b = VisualTreeHelper.GetDescendantBounds(g);

/// new a RenderTargetBitmap with actual size of c
RenderTargetBitmap r = new RenderTargetBitmap((int)b.Width, (int)b.Height, 96, 96, PixelFormats.Pbgra32);

/// Render visual
r.Render(g);

/// Create BitmapFrame as ImageSource
BitmapFrame BitF= BitmapFrame.Create(r);

/// Get Byte[]
byte[] Img = GetImageSourceByte(BitF);




在此感謝 James 的指點

2009年9月15日 星期二

C# BinaryWriter and BinaryReader 應用

一個簡單的應用,不過現在還用不太到,先寫起來作個紀錄

Code 大概是這樣, 將一段字串和一個圖片檔一起存到一個 txt 的 file , 在從file 裡面讀出之前存入的字串和圖片

兩個 function
1. SaveFileByBinaryWrite
2. LoadFileByBinaryReader


Code 如下


SaveFileByBinaryWrite :


/**
* @name SaveFileByBinaryWrite
*
* Save the file by using BinaryWrite method,
* the file include sample description and the image source binary array
*
*
* @param ImgFileRoot [in] - the image file path
* @param Description1 [in] - sample description 1
* @param Description2 [in] - sample description 2
* @param newFile [in] - the new file path
*
*/
public void SaveFileByBinaryWrite(string ImgFileRoot, string Description1, string Description2, string NewFile)
{

/// Open FIleStream to transform image to byte array "MyData"
FileStream FsImageSource = new FileStream(ImgFileRoot, FileMode.OpenOrCreate, FileAccess.Read);
byte[] MyData = new byte[FsImageSource.Length];
FsImageSource.Read(MyData, 0, System.Convert.ToInt32(FsImageSource.Length));
FsImageSource.Close();


/// Open fileStream to write the information to the txt file
FileStream fs = new FileStream(NewFile, FileMode.CreateNew);

/// Open BinaryWriter
BinaryWriter bw = new BinaryWriter(fs);

/// Write information
bw.Write(Description1);
bw.Write(Description2);

/// Set the next write start position
/// In there , set 300
bw.Seek(300, SeekOrigin.Begin);

/// Write byte array MyData begin MyData[0] and length is MyData.Length
bw.Write(MyData, 0, MyData.Length);


/// Close the BinaryWriter and fileStream
bw.Close();
fs.Close();

}




LoadFileByBinaryReader:


/**
* @name LoadFileByBinaryReader
*
* Load the file by using BinaryRead method,
* the file include sample description and the image source binary array
*
*
* @param FileRoot [in] - the file path
*
*
* @return the BitmapImage to shw the image
*
*/
public BitmapImage LoadFileByBinaryReader(string FileRoot)
{

/// Set the Description Length
int DescriptionLength = 300;

/// Open FIleStream to transform image to byte array "MyData"
FileStream fs = new FileStream(FileRoot, FileMode.OpenOrCreate, FileAccess.Read);

/// Open BinaryReader read the FileStream
BinaryReader br = new BinaryReader(fs);

/// Declare the description char array
/// In there length is 300
char[] CharDescripion = new char[DescriptionLength];

/// Write the binary array in CharDescripion , start position 0 and length 300
br.Read(CharDescripion, 0, DescriptionLength);

/// Declare the string dscription
string Descripion = "";


/// Write the Char information to the string Descripion
for (int i = 1; i < DescriptionLength ; i++)
/// when no file break

if (CharDescripion[i] == '\0')
break;
Descripion = Descripion + CharDescripion[i];
}

/// Declare the byte array to get the image
byte[] MyData = new byte[fs.Length - DescriptionLength];

/// Get the ByteLength
int ByteLength = System.Convert.ToInt32(fs.Length - DescriptionLength);
/// Write the binary array in MyData, start position 0 and length ByteLength fs.Read(MyData, 0, ByteLength);
/// Close FIleStream
fs.Close();
/// Put the image byte[] to MemoryStream
MemoryStream ms = new MemoryStream(MyData);
/// Declare BitmapImage Bi
BitmapImage
Bi = new BitmapImage();
Bi.BeginInit();
/// Set Bi source from MemoryStream
Bi.StreamSource = ms;
Bi.EndInit();
return Bi;
}

2009年9月11日 星期五

轉貼 從網路取得圖片 儲存 成 Byte[] by C #

資料來源

http://bytes.com/topic/c-sharp/answers/235707-save-image-url


這裡有用到 BinaryReader. ReadBytes(count )的 function 可以參考MSDN的說明

http://msdn.microsoft.com/zh-tw/library/system.io.binaryreader.readbytes%28VS.80%29.aspx


其中 count 表示要讀取的位元組數目, 此範例 設 500000,
實際圖片轉換成byte[]必須比這個數目小,否則會lose 資料,
儲存完成 範例的 byte[] b 會依據實際的大小作調整

Code 如下




static public byte[] GetBytesFromUrl(string url)
{
byte[] b;
HttpWebRequest myReq = (HttpWebRequest)WebRequest.Create(url);
WebResponse myResp = myReq.GetResponse();

Stream stream = myResp.GetResponseStream();
//int i;
using (BinaryReader br = new BinaryReader(stream))
{
//i = (int)(stream.Length);
b = br.ReadBytes(500000);
br.Close();
}
myResp.Close();
return b;
}




還有將byte[] 儲存成image 的函式




static public void WriteBytesToFile(string fileName, byte[] content)
{
FileStream fs = new FileStream(fileName, FileMode.Create);
BinaryWriter w = new BinaryWriter(fs);
try
{
w.Write(content);
}
finally
{
fs.Close();
w.Close();
}

}


2009年9月10日 星期四

Get Image form Web by C#

以下範例 簡單的說明c# 取得位在網路上圖片的方法, 並將圖片暫存成 BitmapImage


ImgSource 為一個url string 如 "http://lh3.ggpht.com/_aUxwb_torSg/SZ5FjN1UkzI/AAAAAAAAAds/0FM7vPHF0Ho/showBorder.png"

Code 如下


public BitmapImage GetImagefromWeb(string ImgSource)
{
/// Declare BitmapImage Bi
BitmapImage Bi = new BitmapImage();

/// Create the requests.
WebRequest requestPic = WebRequest.Create(ImgSource);

/// Se proxy
/// if web request by proxy
IWebProxy iProxy = WebRequest.DefaultWebProxy;

/// Get potentially, setup credentials on the proxy here
iProxy.Credentials = CredentialCache.DefaultCredentials;

/// Set proxy
requestPic.Proxy = iProxy;


/// Get response
WebResponse responsePic = requestPic.GetResponse();



Bi.BeginInit();

/// Set Bi source from Stream
Bi.StreamSource = responsePic.GetResponseStream();

Bi.EndInit();



return Bi;

}

圖片存取 in sqlite by C#

儲存圖片在資料庫中 可以將圖片轉成一種 blob type 的資料型態, 在儲存在資料庫中。

Blob 的相關用法用很多, 如以下的例子 是用 java 存取 mysql 為例
http://caterpillar.onlyfun.net/Gossip/HibernateGossip/BlobClob.html

在這裡,將使用 C# 將圖片儲存在 sqlite 上

這裡參考了 這一篇文章 http://sqlite.phxsoftware.com/forums/p/324/1329.aspx#1329

我的範例大致描述一下


此範例有使用 System.Data.SQLite; library , 如何使用 見

C sharp or .Net 使用sqlite 設定




有四個物件在視窗上

名稱 函式 說明
---------------------------------------------------------
CreateDB CreateDB_Click 建立資料庫
SaveToDB Save_Click 將圖片儲存在資料庫
LoadImageFromDB Load_Click 將圖片重資料庫讀出
imageExample null 顯示圖片的物件


顯示畫面如下



若 資料庫 及圖片以儲存 按下 LoadImageFromDB 就會重資料庫讀取檔案並顯示




CODE 如下





using System;
using System.Collections.Generic;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

using System.Data.SQLite;
using System.IO;
using System.Data;


namespace SQLiteBlobTest
{

/// Interaction logic for Window1.xaml

public partial class Window1 : Window
{

/// Set Database Root
string DataBaseRoot = Directory.GetCurrentDirectory() + "\\TestBlobDB.db";

public Window1()
{
InitializeComponent();
}



/**
* @name CreateDataBase
*
* Create Database "TestBlobDB.db",
*
*
* Must import System.Data.SQLite or it not work
* @param DataBaseRoot [in] the data base root
*
*/
public static void CreateDataBase(string DataBaseRoot)
{

/// Creat Database
SQLiteConnection.CreateFile(DataBaseRoot);

/// Open Database and set password
SQLiteConnection cnn = new SQLiteConnection("Data Source=" + DataBaseRoot);

/// Open connect
cnn.Open();

/// Close connect
cnn.Close();

}



/**
* @name CreateBlobTable
*
* Create table whcih hava two column
* Name , type is nvarchar(40) , to record the name
* Image , type is BLOB , to record the image with byte[]
*
* Must import System.Data.SQLite or not work
* @param DataBaseRoot [in] the data base root
*/
public void CreateBlobTable(string DataBaseRoot)
{

/// Open Database
SQLiteConnection cnn = new SQLiteConnection("Data Source=" + DataBaseRoot );

/// Open connect
cnn.Open();

/// Define SQLite Command object
SQLiteCommand cmd = new SQLiteCommand();
cmd.Connection = cnn;

/// Set commend to create table
cmd.CommandText = "CREATE TABLE [BlobTable] (Name nvarchar(40), Image BLOB)";

/// Execute the command, iF have exist show error message
cmd.ExecuteNonQuery();

/// Close connect
cnn.Close();
}



/**
* @name CheckDataBaseExist
*
* Check database exist or not
*
* @param DataBaseRoot [in] the data base root
* @return True if exist, otherwise false
*
*/
public Boolean CheckDataBaseExist(string DataBaseRoot)
{

/// Set return value
Boolean ExistOrNot;

/// Check file is exits
if (File.Exists(DataBaseRoot))
{
ExistOrNot = true;
}
else
{
ExistOrNot = false;
}

return ExistOrNot;
}





/**
* @name CreateDB_Click
*
* When click this button , it will create database and table
*
*
*/
private void CreateDB_Click(object sender, RoutedEventArgs e)
{

/// Set Database Root
string DataBaseRoot = this.DataBaseRoot;

/// Flag id database exist
bool FlagIsDBExist = CheckDataBaseExist(DataBaseRoot);


if (FlagIsDBExist)
{
MessageBox.Show("The Database is already exist");
}
else
{
/// Create database and table "BlobTable"
CreateDataBase(DataBaseRoot);
CreateBlobTable(DataBaseRoot);
}

}




/**
* @name Save_Click
*
* When click this button , it will save the image from cumputer to the database
*
*
*/
private void Save_Click(object sender, RoutedEventArgs e)
{


/// Set Database Root
string DataBaseRoot = this.DataBaseRoot;

/// Open Database
SQLiteConnection cnn = new SQLiteConnection("Data Source=" + DataBaseRoot);

/// Open connect
cnn.Open();

/// Define SQLite Command object
SQLiteCommand cmd = new SQLiteCommand();
cmd.Connection = cnn;



/// Open FIleStream to transform image to byte array "MyData"
/// @"C:\20090908002chiachunchuang.jpg" is your image root
FileStream fs = new FileStream(@"C:\20090908002chiachunchuang.jpg", FileMode.OpenOrCreate, FileAccess.Read);
byte[] MyData = new byte[fs.Length];
fs.Read(MyData, 0, System.Convert.ToInt32(fs.Length));
fs.Close();


/// Set commend to save the date to database
cmd.CommandText = "INSERT INTO BlobTable VALUES( 'Test', @blobdata)";
/// When using blob type using the commend to let db save blob type
cmd.Parameters.AddWithValue("@blobdata", MyData);

/// Execute the command
cmd.ExecuteNonQuery();

/// Close connect
cnn.Close();

}


/**
* @name Load_Click
*
* When click this button , it get the image from database and show on windows
*
*
*/
private void Load_Click(object sender, RoutedEventArgs e)
{

/// Declare the byte[] to record the image imformation
byte[] MyData=null;

/// Set Database Root
string DataBaseRoot = this.DataBaseRoot;

/// Open Database
SQLiteConnection cnn = new SQLiteConnection("Data Source=" + DataBaseRoot);

/// Open connect
cnn.Open();

/// Define SQLite Command object
SQLiteCommand cmd = new SQLiteCommand();
cmd.Connection = cnn;

/// Set commend to get value
cmd.CommandText = "Select * from BlobTable";

/// CommandBehavior -> using System.Data;
/// Read all information
using (SQLiteDataReader dr = cmd.ExecuteReader(CommandBehavior.CloseConnection))
{

while (dr.Read())
{
/// Get the value from db
MyData = (Byte[])dr.GetValue(1);

}
}


cnn.Close();



/// Put the image byte[] to MemoryStream
MemoryStream ms = new MemoryStream(MyData);

/// Declare BitmapImage Bi
BitmapImage Bi = new BitmapImage();

Bi.BeginInit();

/// Set Bi source from MemoryStream
Bi.StreamSource = ms;

Bi.EndInit();

/// Set the imageExample's source and it will show on windows
imageExample.Source = Bi;


}





}






}



2009年9月4日 星期五

C sharp 使用 httpRequest 取得 google Auth token

直接使用Google api 來登入 Google 的服務 雖然很方便, 但是每用一次就必須重新驗證一次, 若有要使用很多服務的話也是一件蠻麻煩的事。

所以 Google 提供了一種 ClientLogin 方式的驗證, 讓使用者只要取得一次驗證碼, 之後就不必一直作驗證的動作

以下 是官方的 說明網站

java 範例之前寫過了 見 使用 java http post 取得 google account (AuthSub)

這裡就說明 C# 的方法

輸入 帳號、 密碼即可

會得到 strResponse 如圖, 但我們只要 auth 的驗證碼就好



所以在此用 Split('=') 的方法找出 需要的字串



/**
* @name GetGoogleAuth
*
* Get Google Auth code
* @return string Auth
*/
public string GetGoogleAuth(string Account, string Password)
{
string Auth="";

try
{
/// Create the request obj
HttpWebRequest req = (HttpWebRequest)WebRequest.Create("https://www.google.com/accounts/ClientLogin");

/// Set proxy
SetProxyServer(req);

/// Set values for the request back
req.Method = "POST";
req.ContentType = "application/x-www-form-urlencoded";
string strNewValue = "accountType=HOSTED_OR_GOOGLE&Email=" + Account +
"&Passwd=" + Password +
"&service=cl&source=Gulp-CalGulp-1.05";
req.ContentLength = strNewValue.Length;


/// Write the request
StreamWriter stOut = new StreamWriter(req.GetRequestStream(), System.Text.Encoding.ASCII);
stOut.Write(strNewValue);
stOut.Close();

/// Do the request to get the response
StreamReader stIn = new StreamReader(req.GetResponse().GetResponseStream());
string strResponse = stIn.ReadToEnd();

/// Split string and set token
string[] parts = strResponse.Split('=');

/// Save the Auth Token
/// Auth Token id in the last string
GoogleAuthToken= parts[parts.Length - 1];

stIn.Close();
Auth = GoogleAuthToken;
}
catch
{
Auth = "";
}

return Auth;

}




/**
* @name SetProxyServer
*
* Set the Proxy Server if have Proxy Server
*
*/
public void SetProxyServer(HttpWebRequest req)
{

IWebProxy iProxy = WebRequest.DefaultWebProxy;
/// potentially, setup credentials on the proxy here
iProxy.Credentials = CredentialCache.DefaultCredentials;
req.Proxy = iProxy;
}