本文整理汇总了C#中Google.GData.Client.Service.StringSend方法的典型用法代码示例。如果您正苦于以下问题:C# Service.StringSend方法的具体用法?C# Service.StringSend怎么用?C# Service.StringSend使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Google.GData.Client.Service
的用法示例。
在下文中一共展示了Service.StringSend方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Main
static void Main(string[] args)
{
if (args.Length < 5)
{
Console.WriteLine("Not enough parameters. Usage is ExecRequest <service> <cmd> <uri> <username> <password>, where cmd is QUERY, UPDATE, INSERT, DELETE");
Console.WriteLine("or");
Console.WriteLine("ExecRequest <service> <cmd> <uri> /a <authsubtoken> - to use a session token");
Console.WriteLine("or");
Console.WriteLine("ExecRequest <service> <cmd> <uri> /e <authsubtoken> - to exchance a one time token for a session token");
return;
}
string s = args[0];
string cmd = args[1];
string targetUri = args[2];
string userName = args[3];
string passWord = args[4];
Service service = new Service(s, ApplicationName);
if (userName.Equals("/a"))
{
Console.WriteLine("Using AuthSubToken: " + passWord);
// password should contain the authsubtoken
GAuthSubRequestFactory factory = new GAuthSubRequestFactory(s, ApplicationName);
factory.Token = passWord;
service.RequestFactory = factory;
}
else if (userName.Equals("/e"))
{
Console.WriteLine("Using Onetime token: " + passWord);
passWord = AuthSubUtil.exchangeForSessionToken(passWord, null);
Console.WriteLine("Exchanged for Session Token: " + passWord);
// password should contain the authsubtoken
GAuthSubRequestFactory factory = new GAuthSubRequestFactory(s, ApplicationName);
factory.Token = passWord;
service.RequestFactory = factory;
}
else
{
Console.WriteLine("Setting user credentials for: " + userName);
service.setUserCredentials(userName, passWord);
}
try
{
if (cmd.Equals("QUERY"))
{
Console.WriteLine("Querying: " + targetUri);
Stream result = service.Query(new Uri(targetUri));
DumpStream(result);
}
if (cmd.Equals("DELETE"))
{
service.Delete(new Uri(targetUri));
Console.WriteLine("successfully deleted: " + targetUri);
}
if (cmd.Equals("POST"))
{
String input = Console.In.ReadToEnd();
Console.Write(input);
Stream result = service.StringSend(new Uri(targetUri), input, GDataRequestType.Insert);
DumpStream(result);
}
if (cmd.Equals("UPDATE"))
{
String input = Console.In.ReadToEnd();
Console.Write(input);
Stream result = service.StringSend(new Uri(targetUri), input, GDataRequestType.Update);
DumpStream(result);
}
} catch (GDataRequestException e)
{
HttpWebResponse response = e.Response as HttpWebResponse;
Console.WriteLine("Error executing request for Verb: " + cmd + ", Errorcode: " + response.StatusCode);
Console.WriteLine(response.StatusDescription);
Console.WriteLine(e.ResponseString);
}
}