我正在尝试使用Restlet发送一个byte [](使用PUT),但我找不到有关如何执行此操作的任何信息.我的代码看起来像这样:
Request request = new Request(Method.PUT, url);
request.setEntity( WHAT DO I PUT HERE?, MediaType.APPLICATION_OCTET_STREAM);
Run Code Online (Sandbox Code Playgroud)
我曾期望找到类似于ByteArrayRepresentation的东西,就像有一个JsonRepresentation和一个StringRepresentation但我找不到任何东西.
我有一个ASP.NET(.NET 4)网站,它使用http PUT作为.ashx通用处理程序.PUT调用源自Silverlight前端.所有在我的本地计算机(Cassini Web服务器)上的VS 2010中工作.
然后我部署到IIS7.5 Win Server 2008 R2框.
silverlight/website很好,但是对.ashx处理程序的PUT调用遇到了Windows登录提示符.
这是本地Intranet,因此Windows身份验证(使用NTLM和协商提供程序)是唯一启用的身份验证.
然后我读到这个:http://blogs.msdn.com/b/joseph_fultz/archive/2009/07/23/enabling-the-put-verb-with-handlers-and-iis-7-0.aspx
我已经按照他的建议,我现在可以通过我的.ashx处理程序进行PUT调用.问题是只有Web服务器的Administrators组中的人才能执行此操作.没人能.他们遇到了Windows登录提示.
知道这可能是什么?
我无法在网络服务器上给公司管理员权限.毫无疑问,他们会切断我的一只手,在我面前吃手,然后告诉我门.
据我所知,你可以通过POST发送JSON数据,但PUT是否应该专门在URI中发送信息,或者你可以同时执行这两项操作吗?
谢谢!
因此,在我修复了"415 media media not supported"错误(不支持415媒体)后,我遇到了一个新问题.我RequestBody总是空着的.当我通过Chrome PostMan发送请求时,我总是得到一个只有空值的序列化实体.我使用Spring (4.2.3.RELEASE),Jackson-databind (2.6.3)并jackson-core (2.6.3)在我的项目.我在我的项目中使用基于注释的配置(@EnableWebMvc以使spring自动发现 HTTPMessageConverters).
其他帖子
我知道stackoverflow上的其他帖子,几乎相同的问题.但他们没有给我答案.此外,大多数帖子都是针对较旧的Spring版本(4.0之前版本),所以现在有些东西完全不同了.
类似帖子:
Spring的@RequestBody在POST上提供空字符串
弹簧控制器
在我的春天,@RestController我有以下代码:
@RequestMapping(value = "/location/update/{id}", method = RequestMethod.PUT)
public UserLocation updateUserLocation(@PathVariable("id") int id, UserLocation user) {
return user;
}
Run Code Online (Sandbox Code Playgroud)
我使用单独的模型类(UserLocation)进行数据绑定.这是因为这样我可以更好地控制我的API发送和接收的数据.
数据绑定类(UserLocation)
UserLocation类包含3个属性,包含构造函数和所需的getter和setter.(我可以公开这些属性,但我首先要解决这个问题).
public class UserLocation {
private Float latitude;
private Float longitude;
private Date lastActive;
}
Run Code Online (Sandbox Code Playgroud)
JSON正文
通过我的AngularJS Ajax调用($http.PUT)我使用以下数据调用spring控制器:
{
"latitude": 52.899370,
"longitude": …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用Jmeter记录我的Web客户端 - 服务器通信.配置Jmeter和浏览器以记录应用程序之后.从客户端到服务器发出post请求时,会发生以下错误.知道如何编码正在记录的URL吗?
java.net.URISyntaxException: Illegal character in query at index 238: http://localhost:8080/updateBoxCorrectionInstantly?examKey=16-17-%3ECBSE-%3ETERM%20I-%3ESA1-%3EVI-%3EScience-%3EA&studentName=AMOGH%20YOGESH%20KALE&studentRollno=3&studentND=-1&sheetName=cb8e806b32e9d670698655e0d2da10e3_img001210.jpg&box={%22$center%22:%22(66.0,%202253.0)%22,%22$conf%22:%22H%22,%22$corrected%22:true,%22$isAdminCorrected%22:true,%22$correction%22:%22-%22,%22$isDrawn%22:false,%22coords%22:[36,2214,96,2292],%22isTitle%22:false,%22pos%22:%22-%22,%22pred%22:%22-%22,%22boxTypeId%22:0,%22score%22:1}
at java.net.URI$Parser.fail(URI.java:2829)
at java.net.URI$Parser.checkChars(URI.java:3002)
at java.net.URI$Parser.parseHierarchical(URI.java:3092)
at java.net.URI$Parser.parse(URI.java:3034)
at java.net.URI.<init>(URI.java:595)
at java.net.URL.toURI(URL.java:949)
at org.apache.jmeter.protocol.http.sampler.HTTPHC4Impl.sample(HTTPHC4Impl.java:232)
at org.apache.jmeter.protocol.http.sampler.HTTPSamplerProxy.sample(HTTPSamplerProxy.java:62)
at org.apache.jmeter.protocol.http.sampler.HTTPSamplerBase.sample(HTTPSamplerBase.java:1075)
at org.apache.jmeter.protocol.http.proxy.Proxy.run(Proxy.java:212)
Run Code Online (Sandbox Code Playgroud) 我正在使用Spring MVC来公开一些RESTful Web服务.其中一个操作在提交表单时调用RESTful PUT操作.
但是,表单不是普通形式,因为它包含文件输入以及常规输入,如文本和复选框.
我已经配置春季REST风格的投入到工作中,并通过添加删除HiddenHttpMethodFilter的web.xml.在我的表单中,我也_method发送了一个隐藏参数.
所有这一切都适用于DELETE,PUT没有文件上传等.当我尝试使用文件上传和表单数据进行PUT时,它给了我一个405.
HTTP Status 405 - Request method 'POST' not supported
Run Code Online (Sandbox Code Playgroud)
我的控制器方法如下所示:
@RequestMapping(value = "/admin/cars/{carId}", method = PUT, headers = "content-type=multipart/form-data")
public String updateCar(@PathVariable("carId") String carId, CarForm form) {
// save and return the right view.
}
Run Code Online (Sandbox Code Playgroud)
我的HTML表单如下所示:
<form action="<c:url value='/admin/cars/${car.id}'/>" method="POST" enctype="multipart/form-data">
<input type="hidden" name="_method" value="PUT" />
<input type="text" name="carName" value="${car.name}" />
<input type="file" name="photo" />
<input type="submit" />
</form>
Run Code Online (Sandbox Code Playgroud)
我正在努力实现使用PUT的可行性吗?如果是这样,如何让Spring MVC明白这一点?
我需要在节点中使用"require"npm命中api.api需要原始数据(不是put字段).如何使用请求npm执行此操作?
示例我需要发送的原始数据:
var body = {
"id": 123,
"squares": [
{
square_id: 345,
color: "#ccc"
},
{
square_id: 777,
color: "#fff"
}
]
}
Run Code Online (Sandbox Code Playgroud)
我正在尝试这个,但它不起作用:
request({
method: "PUT",
uri: UPDATE_GAME,
multipart: [{
'content-type': 'application/json',
body: JSON.stringify(body)
}]
}
Run Code Online (Sandbox Code Playgroud) 如果我使用a UUID来将实体标识为我的REST端点的URI的一部分:
/entities/<uuid>/
Run Code Online (Sandbox Code Playgroud)
这UUID是由客户在创建新实体时生成的,就使用PUTvs而言,是否有最佳实践POST?换句话说,它UUID是由客户端生成的,而不是由服务器生成的.
如果我要使用PUT,是否预期消息有效负载也包含UUID?在这种情况下,消息以及标识实体的URI都将包含UUID.
有关规范,请参阅:REST RFC
我是Unity的新手,在Unity中遇到RESTFul的一些问题.我想使用HTTP PUT更新服务器上的一些数据,但正如我在搜索网络时收到的那样,Unity中的WWWW类不支持HTTP PUT.我还尝试了一些与HTTP PUT相关的HttpWebRequest示例,但总是收到错误代码400:错误请求.
我怎么解决这个问题?我是否必须在更新时列出所有键值对,或者只需要列出我想要更改值的对?