我想使用JQuery-File-Upload上传文件,但使用HTTP"PUT"而不是multipart-forms.根据他们的网站:
- Multipart and file contents stream uploads:
Files can be uploaded as standard "multipart/form-data" or file contents stream (HTTP PUT file upload).
Run Code Online (Sandbox Code Playgroud)
但我在他们的文档中找不到如何做到这一点.有人可以帮忙吗?
我搜索过,但我找不到答案.我有一个RESTful API来管理基本的CRUD.我正在尝试使用PUT创建更新方法,但我无法检索params值.我正在使用Postman发出请求,我的请求如下:
网址
http://localhost/api/update/987654321
Run Code Online (Sandbox Code Playgroud)
PARAMS
id = 987654321
name = John Smith
age = 35
Run Code Online (Sandbox Code Playgroud)
PHP
$app = new Slim();
$app->put('/update/:id', function( $id ) use( $app ){
var_dump([
'id' => $id,
'name' => $app->request->put('name'),
'age' => $app->request->put('age')
]);
});
Run Code Online (Sandbox Code Playgroud)
我的var_dump()结果是:
array(3) {
["id"]=>
string(9) "987654321"
["name"]=>
NULL
["age"]=>
NULL
}
Run Code Online (Sandbox Code Playgroud)
怎么了?任何的想法?
从版本2.5.7开始, Spring Data REST无法正确执行PUT请求以更新具有关联资源的资源.与按预期工作的PATCH请求不同!
例如,Person与多对一关联Addres.如果我们使用SDR v.2.5.6(Spring Boot v.1.4.3)执行PUT请求,那么一切正常.但是,如果我们切换到2.5.7版(即Spring Boot v.1.4.4),那么我们会收到一个错误:
无法构造Address的实例:没有String-argument构造函数/工厂方法从String值反序列化
其他类型的关联也会发生同样的情况,例如一对多(单向和双向) - 请参阅我的示例应用程序代码和测试.
从1.4.4开始,Spring Boot的所有版本都存在此问题,包括最新的稳定1.5.6版本,以及最新的2.0.0-SNAPSHOT版本!
要解决这种情况,我们可以切换到SDR v.2.5.6(Spring Boot v.1.4.3).
我准备了一个邮递员的请求集合,以帮助您解决问题:SDR PUT问题
更新2017-08-14
我找到了如何避免错误Can not construct instance of Address: no String-argument constructor/factory method to deserialize from String value.
由于我在这个项目中使用Lombok,因此有必要告诉Lombok禁止@ConstructorProperties在生成的构造函数中使用注释
.所以我lombok.anyConstructor.suppressConstructorProperties=true在'lombok.config'文件中设置,错误消失了.
不幸的是,发现了一个新问题 - PUT请求根本不更新关联的对象!
以下示例说明了这一点.当我们尝试通过将他的地址从addresses/1(初始值)更改为addresses/2- 来更新Person时,它仍然是相同的:addresses/1!与之前的问题一样,自1.4.4以来,这一问题出现在Spring Boot的 …
我想在github上为团队添加一个repo,因此:
curl -i -u username:password -X PUT -d "" https://api.github.com/teams/:team/repos/:user/:repo
Run Code Online (Sandbox Code Playgroud)
(细节遗漏)
几乎不是那么详细的文档中指出的.
这给了一个500 Internal server error.
如果我遗漏-d""它给出一个411 "Content-Length required",
如果我指定(使用-H)"Content-Length: 0":再次500错误...
任何线索?
[编辑]答案:API提供了虚假的回复,文档在那里不是很好:
" :team"是系统分配的数字ID(不是你给它的名字...... arg!) - 它只能从API获得查询或在您访问团队时查看浏览器中的URL.多么优雅.
此外,您似乎不能在您的帐户下分配任何 ol'回购 - 它必须位于团队所属的"组织"中.
去那里显然需要一些有趣的体操...如果我弄清楚的话会更多.到目前为止GitHub Usablity评级:(1-10)2.
[编辑2]结论:github上的文件规定了这个:
添加团队回购
为了向团队添加回购,经过身份验证的用户必须是与该团队关联的组织的所有者.
PUT /teams/:id/repos/:user/:repo
Run Code Online (Sandbox Code Playgroud)
不行.是什么做的工作是这样的:
PUT /teams/:id/repos/:org/:repo
Run Code Online (Sandbox Code Playgroud)
将" :user" 替换为" :org"(团队所属的"组织"的名称).
案件结案.希望这有助于有人避免同样有趣的下午.
我有一个使用Backbone.js的基本应用程序,它没有进行PUT调用(更新模型).从前端开始,我调用模型save函数不会进行PUT调用; 但是,如果我用它替换它destroy,它会对后端进行DELETE调用.任何人都知道可能是什么问题?未触发PUT请求的saveTask功能是该功能.
App.Views.Task = Backbone.View.extend({
template: _.template("<label>ID:</label><input type='text' id='taskId' name='id' value='<%= _id %>' disabled /><br><label>Title:</label><input type='text' id='title' name='title' value='<%= title %>' required/><br><label>Content:</label><input type='text' id='content' name='content' value='<%= content %>'/><br><button class='save'>Save</button>"),
events: {
"change input":"change",
"click .save":"saveTask"
},
render: function(eventName){
$(this.el).html(this.template(this.model.toJSON()));
//console.log(this.generateTemplate());
return this;
},
change: function(event){
var target = event.target;
console.log('changing ' + target.id + ' from: ' + target.defaultValue + ' to: ' + target.value);
change[target.name] = target.value;
this.model.set(change);*/
},
saveTask: function(){
this.model.set({
title:$("#title").val(), …Run Code Online (Sandbox Code Playgroud) 我正在使用django-rest-framework,我需要在URL文件中映射两个具有相同url的通用视图(iḿ已经使用了URL而不是Routes):
我需要在一个url(例如/ api/places/222)中允许GET,PUT和DELETE动词,并允许每个人使用相关的Entity Place获取每个字段,但只允许使用相同的url更新(PUT)一个字段.
放置实体:
- id (not required in PUT)
- name (required always)
- date (not required in PUT but required in POST)
Run Code Online (Sandbox Code Playgroud)
网址
url(r'^api/places/(?P<pk>\d+)/?$', PlacesDetail.as_view(), name='places-detail'),
Run Code Online (Sandbox Code Playgroud)
我尝试使用RetrieveDestroyAPIView和UpdateAPIView,但我不能只使用一个URL.
我有一个问题,骨干PUT请求返回405(方法不允许).发生这种情况是因为代码中的model.save()没有发送到具有模型ID的模型URL.
这是PUT.
Remote Address:::1:670
Request URL:http://localhost:670/api/contacts
Request Method:PUT
Status Code:405 Method Not Allowed
Request Headersview source
Accept:application/json, text/javascript, */*; q=0.01
Accept-Encoding:gzip,deflate,sdch
Accept-Language:en-GB,en-US;q=0.8,en;q=0.6
Authorization:Bearer YLPwKSpBsBrFUemRHdjz....
Connection:keep-alive
Content-Length:417
Content-Type:application/json
Host:localhost:670
Origin:http://localhost:660
Referer:http://localhost:660/
User-Agent:Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/34.0.1847.116 Safari/537.36
Request Payloadview source
{id:1, ContactOrganisation:Cow on a Mission, ContactPerson:Ben Drury, Phone:07980567574,…}
Address: "----"
ContactOrganisation: "----"
ContactPerson: "Ben"
CreatedBy: "----"
CreatedOn: "2014-03-03T16:40:50.037"
Description: "----"
Email: "---"
Organistion: "----"
Phone: "----"
Website: "http://www.cogiva.com"
id: 1
Response Headersview source
Access-Control-Allow-Headers:Authorization, Content-Type
Access-Control-Allow-Methods:GET, …Run Code Online (Sandbox Code Playgroud) 我只是想知道SparseArray put(...)和append(...)SparseArray 之间的区别是什么?
从官方文档:
append(...) :将键/值对放入数组中,针对键大于数组中所有现有键的情况进行优化.put(...) :添加从指定键到指定值的映射,如果有指定键,则替换先前映射.但我只是不明白:s
谢谢你的帮助 !
我试图在我的视图集上测试我的更新方法.视图集是取自drf的模型视图集.要更新我需要发送一个put请求.由于并不总是支持这两种方法告诉服务器我正在发出一个put请求,第一种不符合我需要的方法是使用一个额外的字段来调用_method并设置它put.由于我需要发布json数据,我需要使用第二种方式,它使用X-HTTP-Method-Override标头.
要在测试用例中发布我的数据,请使用以下代码:
header = {'X_HTTP_METHOD_OVERRIDE': 'PUT'}
response = client.post('/model/1/', content_type='application/json', data=post_data_clean, **header)
Run Code Online (Sandbox Code Playgroud)
但不幸的是,我得到的结果是{'detail':'Method POST not allowed.'}.我使用插件(Postman)测试了服务器的行为,我也指定了X-HTTP-Method-Override标头.没有例外.我现在需要知道如何正确地将标头传递给django测试客户端,否则测试会在这里变得非常烦人.
python django put django-rest-framework x-http-method-override
我尝试使用XML API将文件上传到Google云端存储.我为每次上传生成了正确的GoogleAccessId,到期日期和签名.奇怪的是我可以使用Postman(Chrome应用程序)PUT文件,所以我确定网址没问题.我只是不能使用我的Android Java程序(它返回给我403错误).执行上传的源代码在此处(基于以下内容:https://cloud.google.com/storage/docs/access-control#Signing-Strings):
URL url;
HttpURLConnection connection;
try {
url = new URL("http://google-testbucket.storage.googleapis.com/testdata.txt?GoogleAccessId=1234567890123@developer.gserviceaccount.com&Expires=1331155464&Signature=BClz9e4UA2MRRDX62TPd8sNpUCxVsqUDG3YGPWvPcwN%2BmWBPqwgUYcOSszCPlgWREeF7oPGowkeKk7J4WApzkzxERdOQmAdrvshKSzUHg8Jqp1lw9tbiJfE2ExdOOIoJVmGLoDeAGnfzCd4fTsWcLbal9sFpqXsQI8IQi1493mw%3D");
connection = (HttpURLConnection) url.openConnection();
connection.setDoOutput(true);
connection.setRequestMethod("PUT");
OutputStreamWriter out = new OutputStreamWriter(connection.getOutputStream());
out.write("Test");
out.close();
Log.i("TAG", "PUT Response code: " + connection.getResponseCode());
} catch (MalformedURLException e) {
e.printStackTrace();
Log.e("TAG", "MalformedURLException");
} catch (ProtocolException e) {
e.printStackTrace();
Log.e("TAG", "ProtocolException");
} catch (IOException e) {
e.printStackTrace();
Log.e("TAG", "IOException");
}
Run Code Online (Sandbox Code Playgroud)
PUT对象的文档:https://cloud.google.com/storage/docs/xml-api/put-object-upload
任何人都可以调查这个问题,并告诉我这个问题可能出现什么问题?
put ×10
android ×2
backbone.js ×2
java ×2
rest ×2
api ×1
append ×1
curl ×1
django ×1
get ×1
github ×1
javascript ×1
jquery ×1
php ×1
python ×1
restful-url ×1
slim ×1
spring-boot ×1