- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
这是我到目前为止所拥有的,但它不起作用:
private void _send1(string file)
{
var client = new RestClient("https://identity.api.rackspacecloud.com/v2.0");
var request = new RestRequest("tokens", Method.POST);
request.RequestFormat = DataFormat.Json;
string test = "{\"auth\":{\"RAX-KSKEY:apiKeyCredentials\"{\"username\":\"";
test += UserName;
test += "\",\"apiKey\":\"";
test += MyToken;
test += "\"}}}";
request.AddBody(serText);
request.AddParameter("application/json", test, ParameterType.RequestBody);
RestResponse response = (RestResponse)client.Execute(request);
// Content = "{\"badRequest\":{\"code\":400,\"message\":\"java.lang.String cannot be cast to org.json.simple.JSONObject\"}}"
}
注意:用户名和 apiKey 是有效的 RackSpace 凭据:-)
谢谢提前
尝试 2:(在网上找到这个)它给了我一个 token ...现在我该怎么办?
private void _send2(string file)
{
Dictionary<string, object> dictAuth = new Dictionary<string, object>();
dictAuth.Add("RAX-KSKEY:apiKeyCredentials", new { username = UserName, apiKey = MyToken });
var auth = new
{
auth = dictAuth
};
RestClient client = new RestClient("https://identity.api.rackspacecloud.com");
RestSharp.RestRequest r = new RestRequest("/v2.0/tokens", Method.POST);
r.AddHeader("Content-Type", "application/json");
r.RequestFormat = DataFormat.Json;
r.AddBody(auth);
RestResponse response = (RestResponse)client.Execute(r);
// Content = "{\"access\":{\"token\":{\"id\":\"AACCvxjTOXA\",\"expires\":\"2016-04-09T21:12:10.316Z\",\"tenant\":{\"id\":\"572045\",\"name\...
}
再进一步:我创建了一个类,用于解析上面第 2 步中的 URL、tenantID 和 token 此数据将传递给 PostFile 调用:
private void PostFile(string url, string tenantID, string token, string file)
{
string fName = Path.GetFileName(file);
RestClient client = new RestClient(url);
string baseURL = string.Format("v1/{0}/Support/{1}", tenantID, fName);
RestRequest r = new RestRequest(baseURL, Method.POST);
r.AddHeader("Content-Type", "text/plain");
r.AddParameter("X-Auth-Token", token);
r.AddFile(fName, file);
RestResponse response = (RestResponse)client.Execute(r);
if( response.StatusCode == System.Net.HttpStatusCode.OK)
{
int x = 0;
}
}
这是最终起作用的:
bool bRetval = false;
string fName = Path.GetFileName(file);
RestClient client = new RestClient(url);
string baseURL = string.Format("/Support/{0}", fName);
RestRequest r = new RestRequest(baseURL, Method.PUT);
r.AddHeader("Content-Type", "text/plain");
r.AddHeader("X-Auth-Token", token);
r.AddFile(fName, file);
RestResponse response = (RestResponse)client.Execute(r);
最佳答案
请参阅上面的帖子,了解导致此问题的支持功能
private bool PostFile(string url, string token, string file)
{
bool bRetval = false;
string fName = Path.GetFileName(file);
RestClient client = new RestClient(url);
string baseURL = string.Format("/Support/{0}", fName);
RestRequest r = new RestRequest(baseURL, Method.PUT);
r.AddHeader("Content-Type", "text/plain");
r.AddHeader("X-Auth-Token", token);
r.AddFile(fName, file);
RestResponse response = (RestResponse)client.Execute(r);
if ( response.StatusCode == System.Net.HttpStatusCode.Created)
{
bRetval = true;
}
return bRetval;
}
关于.net-4.0 - 如何使用 RESTSharp 和 .net 4.0 将文件上传到机架空间?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36509279/
Kafka引入了rack-id,以便在整个机架发生故障时提供冗余功能。有一个最小同步副本设置,用于指定生产者收到确认之前需要同步的最小副本数量(-1/所有配置)。有一个不干净的领导者选举设置,用于指定
Kafka引入了rack-id,以便在整个机架发生故障时提供冗余功能。有一个最小同步副本设置,用于指定生产者收到确认之前需要同步的最小副本数量(-1/所有配置)。有一个不干净的领导者选举设置,用于指定
我正在尝试使用 Sinatra、Ruby、rack、haml、pony 和 SendGrid 构建一个应用程序,并使用 git 和 RVM 部署在 Heroku 上。该应用程序是一个博客变体,应该发送
我正在尝试将 Rack OAuth-2 server 集成到我的 sinatra 应用程序中,以便在 web-server flow implementation 中使用它,但我无法使其工作:(。我在
我按照这些说明为 Rails 3.07 安装了 rack ssl:http://www.simonecarletti.com/blog/2011/05/configuring-rails-3-http
我在我的 Rails 3.1 应用程序中使用 Rack::SSL 来启用 SSL 连接。 我已将 gem 'rack-ssl' 添加到我的 Gemfile 和 require 'rack/ssl' c
当我尝试将未分配的辅助分片分配给节点时出现错误。 { "error": { "root_cause": [ { "type": "remote_transpor
我是一名优秀的程序员,十分优秀!