本文整理汇总了C#中Hammock.RestRequest.AddPostContent方法的典型用法代码示例。如果您正苦于以下问题:C# RestRequest.AddPostContent方法的具体用法?C# RestRequest.AddPostContent怎么用?C# RestRequest.AddPostContent使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Hammock.RestRequest
的用法示例。
在下文中一共展示了RestRequest.AddPostContent方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: LogIn
public ActionResult LogIn(string assertion)
{
var client = new RestClient()
{
Authority = "https://browserid.org"
};
var request = new RestRequest
{
Path = "/verify",
Method = WebMethod.Post,
};
var audience = new UriBuilder(Request.Url.Scheme, Request.Url.Host, Request.Url.Port).Uri.ToString();
var postData = string.Format("assertion={0}&audience={1}", assertion, audience);
request.AddPostContent(Encoding.Default.GetBytes(postData));
var response = client.Request(request);
var json = JsonObject.Parse(response.Content);
if (json["status"].ReadAs<string>() == "okay")
{
// This logs the user in if we have an account for that email address,
// or creates it otherwise
SessionUser.Current.Email = json["email"].ReadAs<string>();
var hashedEmail = HashHelper.Hash(SessionUser.Current.Email);
if (_Client.Get(hashedEmail) == null)
{
_Client.Store(StoreMode.Add, hashedEmail, string.Empty);
}
return Json(SessionUser.Current.Email);
}
else
{
var message = new KeyValuePair<string, JsonValue>("message", "Could not log you in");
var status = new KeyValuePair<string, JsonValue>("status", false);
return Json(new JsonObject(message, status));
}
}
示例2: postMessageToTwitter
private void postMessageToTwitter()
{
var credentials = new OAuthCredentials
{
Type = OAuthType.ProtectedResource,
SignatureMethod = OAuthSignatureMethod.HmacSha1,
ParameterHandling = OAuthParameterHandling.HttpAuthorizationHeader,
ConsumerKey = AppSettings.TwitterConsumerKey,
ConsumerSecret = AppSettings.TwitterConsumerKeySecret,
Token = this.accessToken,
TokenSecret = this.accessTokenSecret,
Version = "1.0"
};
var restClient = new RestClient
{
Authority = AppSettings.TwitterStatusUpdateUrl,
HasElevatedPermissions = true,
Credentials = credentials,
Method = WebMethod.Post
};
restClient.AddHeader("Content-Type", "application/x-www-form-urlencoded");
var restRequest = new RestRequest
{
Path = "1/statuses/update.xml?status=" + this.postMessage
};
var ByteData = Encoding.UTF8.GetBytes(this.postMessage);
restRequest.AddPostContent(ByteData);
restClient.BeginRequest(restRequest, new RestCallback(postFinished));
}
示例3: Tweet
public static void Tweet(string tweet)
{
var credentials = new OAuthCredentials
{
Type = OAuthType.ProtectedResource,
SignatureMethod = OAuthSignatureMethod.HmacSha1,
ParameterHandling = OAuthParameterHandling.HttpAuthorizationHeader,
ConsumerKey = TwitterSettings.ConsumerKey,
ConsumerSecret = TwitterSettings.ConsumerKeySecret,
Token = IsolatedStorageSettings.ApplicationSettings[TWITTER_ACCESS_TOKEN_KEY].ToString(), //The request Token
TokenSecret = IsolatedStorageSettings.ApplicationSettings[TWITTER_ACCESS_SECRET_KEY].ToString(),
Version = "1.0"
};
var restClient = new RestClient
{
Authority = TwitterSettings.StatusUpdateUrl,
HasElevatedPermissions = true,
Credentials = credentials,
Method = WebMethod.Post
};
restClient.AddHeader("Content-Type", "application/x-www-form-urlencoded");
// Create a Rest Request and fire it
var restRequest = new RestRequest
{
Path = "1/statuses/update.xml?status=" + tweet
};
var ByteData = Encoding.UTF8.GetBytes(tweet);
restRequest.AddPostContent(ByteData);
restClient.BeginRequest(restRequest, new RestCallback(TweetCallback));
}
示例4: SendRegistrationToServer
static void SendRegistrationToServer(IEnumerable<RegistrationInfo> regs)
{
// I'm just so sorry about all this crap.
string separator = "¬";
string urls = "", tokens = "", names = "", types = "";
string version = WPVersion == OSVersion.WP8 ? "8" : "7";
foreach (var reg in regs)
{
urls += reg.ChannelUri + separator;
names += reg.User.ScreenName + separator;
tokens += Library.Encrypting.EncodeTokens(reg.User.Key, reg.User.Secret) + separator;
types += reg.Type + separator;
}
// Remove last separator
urls.Substring(0, urls.Length - 1);
tokens.Substring(0, tokens.Length - 1);
names.Substring(0, names.Length - 1);
types.Substring(0, types.Length - 1);
string postContents = "{\"AccessTokens\" : \"" + tokens + "\",\"PushUris\" : \"" + urls + "\",\"Usernames\" : \"" + names + "\",\"Types\" : \"" + types + "\",\"OSVersion\" : \"" + version + "\"}";
var request = new RestRequest();
request.Path = Library.SensitiveData.PushRegisterPostUriFormat;
request.Method = WebMethod.Post;
request.AddHeader("Content-Type", "application/json");
request.AddPostContent(Encoding.UTF8.GetBytes(postContents));
try
{
new RestClient().BeginRequest(request, (req, resp, s) =>
{
ReportRegisterToUser(resp);
});
}
catch (Exception)
{
}
}
示例5: BeginRequest
public void BeginRequest(string path, IDictionary<string, string> parameters, IDictionary<string, File> files, WebMethod method, RestCallback callback, object userState)
{
var request = new RestRequest
{
Path = path,
Method = method
};
if (files != null)
{
foreach (var f in files)
request.AddFile(f.Key, f.Value.FileName, f.Value.FilePath);
}
if (Credentials != null)
request.Credentials = Credentials;
if (parameters != null)
foreach (var p in parameters)
{
request.AddParameter(p.Key, p.Value);
}
#if !SILVERLIGHT
if (files != null)
foreach (var f in files)
{
byte[] rawData = System.IO.File.ReadAllBytes(f.Value.FilePath);
request.AddPostContent(rawData);
}
//request.AddFile(f.Key, f.Value.FileName, f.Value.FilePath, "image/jpeg");
#endif
Client.BeginRequest(request, (req, res, obj) =>
{
if (callback != null)
callback(req, res, obj);
}, userState);
}