我有一个REST Web服务和android.现在我想使用android来请求Http Put来调用Web服务.在我的REST Web服务中,如果用户想要做Http Put,他可以在终端中请求如下:
curl -H"Content-Type:application/vnd.org.snia.cdmi.dataobject"-v -T /home/student1/a.jpg http:// localhost:8080/user1/folder/a.jpg
我的问题是如何在Android中使用HttpPut设置-T /home/student1/a.jpg?
我的基于ZF2的应用程序和Backbone在前端有问题.在某个地方,我跑步
this.model.save({
city_id: parseInt( this.$el.find( '#city_id' ).val() ),
from: this.$el.find( '#from' ).val(),
to: this.$el.find( '#to' ).val(),
price: parseInt( this.$el.find( '#price' ).val() )
});
Run Code Online (Sandbox Code Playgroud)
我打开Chrome嗅探器并查看请求详细信息:
PUT /account/trip/2 HTTP/1.1
Host: jamydays.ru
Connection: keep-alive
Content-Length: 186
Accept: application/json, text/javascript, */*; q=0.01
Origin: http://jamydays.ru
X-Requested-With: XMLHttpRequest
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_5) AppleWebKit/537.31 (KHTML, like Gecko) Chrome/26.0.1410.65 Safari/537.31
Content-Type: application/json
Referer: http://jamydays.ru/account
Accept-Encoding: gzip,deflate,sdch
Accept-Language: en-US,en;q=0.8
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.3
Cookie: PHPSESSID=pekjbefmi1jn01q5fgm4gu6jk0; _ym_visorc=w
Run Code Online (Sandbox Code Playgroud)
请求有效负载是:
{"from_formatted":"10 маÑ","to_formatted":"19 маÑ","url":"/account/trip","id":2,"city_id":65170,"city":"Baardheere","from":"10-05-2013","to":"19-05-2013","price":500,"is_active":1}
Run Code Online (Sandbox Code Playgroud)
用于处理此请求的Conroller运行适当的操作:
class TripController extends AbstractRestfulController{
...
public …Run Code Online (Sandbox Code Playgroud) I implemented an API that renames a company as follows:
PUT /companies/A
{
"name": "B"
}
Run Code Online (Sandbox Code Playgroud)
will return HTTP 301 with the Location header pointing at the company's new URI: /companies/B.
How can I make this operation idempotent with and without If-Match headers?
Without If-Match header: if a user tries to rename a non-existent company, I'd expect the server to return HTTP 404 but I can't do so because then legitimate rename operations wouldn't be idempotent (they'd return 301 …
其实我的问题很简短.
如何从ASP.NET Web API POST或PUT获取HttpPostedFile?
我确实看到我可以从请求中获取各种信息,如Request.Header,Request.Content,Request.Properties.在哪里可以找到我传递的文件,如何从中创建HttpPostedFile?
提前致谢!
我需要添加
router= "/update/id" in my code, where "id" has to be rendered dynamically based on values by *ngFor directive. (i.e) {{obj.id}}.So that id gets rendered dynamically
Run Code Online (Sandbox Code Playgroud)
这该怎么做?
我正在尝试使用以下代码从 Google Cloud 生成下载和上传链接,以查看和上传文件:
public class Test {
public static void main(String[] args) throws IOException {
Storage storage = StorageOptions.newBuilder().setCredentials(
ServiceAccountCredentials.fromStream(new FileInputStream("C:/cred/Key.json")))
.build()
.getService();
String filePath = "file/path/";
File file = new File(filePath);
byte[] bytes = Utilities.fileToByteArray(file);
String mimeType = Utilities.getMimeType(bytes);
BlobId blobId = BlobId.of("bucket", file.getName());
BlobInfo blobInfo = BlobInfo.newBuilder(blobId).setContentType(mimeType).build();
URL urlGet = storage
.signUrl(BlobInfo.newBuilder("bucket", "object").build(), 1, TimeUnit.HOURS,
SignUrlOption.httpMethod(HttpMethod.GET));
URL urlPut = storage
.signUrl(blobInfo, 1, TimeUnit.DAYS, SignUrlOption.httpMethod(HttpMethod.PUT),
SignUrlOption.withContentType());
System.out.println(urlGet);
System.out.println(urlPut);
}
}
Run Code Online (Sandbox Code Playgroud)
urlGet包含下载链接并urlPut包含上传链接。当我运行该程序时,我得到以下输出:
https://storage.googleapis.com/roshanbucket/jasperviewpdf?GoogleAccessId=myservice@deft-idiom-234709.iam.gserviceaccount.com&Expires=1552986620&Signature=OZl6M4uMkigu6JBMYoDumgs8P4EC%2BtcK44zHMPkG2xzq3hFfsrj8YYRRtajI8diz64vdCX54nct3wuEpXNRwcnzCmq4KdD53%2B8gbERNuttm8K6%2BlZDLGF3wng%2BCSMzghbGbLnYaZRiZbvjCG%2B3ObBUg9ZiY0qRlif9nyGFftsGUF9GGHvHP6HWP51DJOAurGytSjf9SA5HKPOw4e%2B%2BP1LltfI7m3WjWhxwnSYz4lVxcR4eksec7ILTi66jnwu1gxXtqp75XTxLp9vQa6RC4dCPGoTridFQcMqm89TVzf58c8krk7apQCR6TWp2tAWuFr2xJ1U5FwFfiBaoSX4A33rw%3D%3D
https://storage.googleapis.com/roshanbucket/pi.jpg?GoogleAccessId=myservice@deft-idiom-234709.iam.gserviceaccount.com&Expires=1553069420&Signature=YHsGTgXIBum9t5M7U%2F9fdibDvzBKttQGh0jxzbYgJkevQbpOh8gRQYOlHdjT86byobDE5TNEGF5VrGFAtI5rhRGxLw0xqcNT%2BYGfvHxAIfAJXy5ormXxWVnVEnwGMafyVLOtdIY4asa0niFu%2B36eaIqtD5UzsjUY%2F18OW%2FwvjfQmhlmsvJ7qSkfD1Oif5Rv6c%2F67z1zT7gz7rB4gTCG6mLALuRrOIwCPO%2BkyzOxP9PhEJkoB7j446v%2BhE%2F0pt0wM2nJ29%2BK3HRUShhccJzzZ%2BZRxgOXeUL44CsnYlssaTThU%2FztyUbsXWXbs2hroTcFxVVtOp7aGeCUs1qjdJkXaEg%3D%3D
Run Code Online (Sandbox Code Playgroud)
当我单击第一个链接(即下载)时,它会毫无问题地呈现存储桶中的文件,但是当我使用第二个链接将文件从我的计算机上传到 Google …
我正在设计REST API,我想知道处理资源更新的推荐方法是什么.更具体地说,我将允许通过PUT资源进行更新,但我应该在PUT请求正文中允许什么?
例如,获取资源http://example.org/api/v1/dogs/packs/p1.GET此资源上的A 将提供以下内容:
Request:
GET http://example.org/api/v1/dogs/packs/p1
Accept: application/xml
Response:
<pack>
<owner>David</owner>
<dogs>
<dog>
<name>Woofer</name>
<breed>Basset Hound</breed>
</dog>
<dog>
<name>Mr. Bones</name>
<breed>Basset Hound</breed>
</dog>
</dogs>
</pack>
Run Code Online (Sandbox Code Playgroud)
假设我想要添加一只狗(Sniffers the Basset Hound),我会支持:
Request:
PUT http://example.org/api/v1/dogs/packs/p1
<dog>
<name>Sniffers</name>
<breed>Basset Hound</breed>
</dog>
Response:
HTTP/1.1 200 OK
Run Code Online (Sandbox Code Playgroud)
要么
Request:
PUT http://example.org/api/v1/dogs/packs/p1
<pack>
<owner>David</owner>
<dogs>
<dog>
<name>Woofer</name>
<breed>Basset Hound</breed>
</dog>
<dog>
<name>Mr. Bones</name>
<breed>Basset Hound</breed>
</dog>
<dog>
<name>Sniffers</name>
<breed>Basset Hound</breed>
</dog>
</dogs>
</pack>
Response:
HTTP/1.1 …Run Code Online (Sandbox Code Playgroud) 下面是一个将文件从本地文件系统上传到远程 Apache 服务器的程序。
程序以 409 冲突错误结束。有什么建议我做错了什么吗?我在 httpd.conf 中打开了 DAV 并授予了所有必要的权限,但我仍然没有运气。如果需要,我可以发布 httpd.conf。
这是代码:
BOUNDARY = "AaB03xZZZZZZ11322321111XSDW"
uri = URI.parse("http://localhost/dropbox/")
file = "/tmp/KEYS.txt"
http = Net::HTTP.new(uri.host, uri.port)
request = Net::HTTP::Put.new(uri.request_uri)
request.body_stream=File.open(file)
request["Content-Type"] = "multipart/form-data"
request.add_field('Content-Length', File.size(file))
request.add_field('session', BOUNDARY)
response=http.request(request)
puts "Request Headers: #{request.to_hash.inspect}"
puts "Sending PUT #{uri.request_uri} to #{uri.host}:#{uri.port}"
puts "Response #{response.code} #{response.message}"
puts "#{response.body}"
puts "Headers: #{response.to_hash.inspect}"
Run Code Online (Sandbox Code Playgroud)
它的输出:
Request Headers: {"accept"=>["*/*"], "host"=>["localhost"], "content-length"=>[88873], "content-type"=>["multipart/form-data"], "session"=>["AaB03xZZZZZZ11322321111XSDW"], "connection"=>["close"]}
Sending PUT /dropbox/ to localhost:80
Response 409 Conflict
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head> …Run Code Online (Sandbox Code Playgroud) 我必须将一些json数据'PUT'发送到服务器.以下代码抛出错误
$rootScope.request.data = {"name": "John", "surname":"Doe"}
var uri = //some REST API
var action = $http({
method: 'PUT',
url: uri,
data: $rootScope.request.data
});
Run Code Online (Sandbox Code Playgroud)
抛出的错误是:
找不到资源的流:资源{displayName ='null',uri ='/ signup'}(org.mule.module.apikit.exception.ApikitRuntimeException).消息有效内容的类型为:NullPayload
但是,当我这样做时,它的工作原理
$rootScope.request.data = {"name": "John", "surname":"Doe"}
var uri = //some REST API
var action = $http.put(uri, $rootScope.request.data);
Run Code Online (Sandbox Code Playgroud)
然后将'action'推入一个数组中,并使用$ q.all触发请求.成功和错误在$ q中处理
想知道他们之间有什么区别?我的第一次请求中是否遗漏了一些内容?
我一直在努力在.NET 4.0中设置WCF REST服务.我有GET请求工作,但任何涉及POST数据到服务器的请求都失败了HTTP 400 Bad Request.
这是我的简单服务:
[ServiceContract]
[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
[ServiceBehavior(InstanceContextMode = InstanceContextMode.PerCall)]
public class Service1
{
[WebGet(UriTemplate = "")]
public string HelloWorld()
{
return "hello world";
}
[WebInvoke(UriTemplate = "", Method = "POST")]
public string HelloWorldPost(string name)
{
return "hello " + name;
}
}
Run Code Online (Sandbox Code Playgroud)
我的Web.config:
<?xml version="1.0"?>
<configuration>
<system.web>
<compilation debug="true" targetFramework="4.0" />
</system.web>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true">
<add name="UrlRoutingModule" type="System.Web.Routing.UrlRoutingModule, System.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
</modules>
</system.webServer>
<system.serviceModel>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true"/>
<protocolMapping>
<add scheme="http" binding="webHttpBinding" /> …Run Code Online (Sandbox Code Playgroud) http-put ×10
http ×3
rest ×3
http-post ×2
android ×1
angular ×1
angularjs ×1
asp.net ×1
backbone.js ×1
httprequest ×1
idempotent ×1
java ×1
net-http ×1
ruby ×1
web-services ×1