如果我想开发一个客户端 - 服务器设计的iPhone应用程序(iPhone设备作为客户端和ac#服务器),有两个问题:
因此,如果我理解正确的,从客户端向服务器发送诸如"创建新用户"之类的消息的过程如下:1.客户端将创建包含命令"CREATE NEW USER"的JSON/XML和新用户详细信息.2.客户端将通过HTTP请求(作为HTTP请求的主体)发送此JSON/XML,其URL在服务器端映射到ac#方法.3.这将在服务器上触发相应的方法,并在数据库上创建新用户.4.服务器将创建包含重播"CREATED"的JSON/XML,并将通过HTTP响应(作为HTTP响应的主体)将其发送到客户端.那是对的吗?
我正在创建RESTful Web服务,其中一些资源是计算或处理功能.例如,用户可以通过提交图像并接收缩放或转换的图像来缩放和转换图像.
根据RESTful Web Services Cookbook第2.5节,我应该使用GET:
Treat the processing function as a resource, and use HTTP GET to fetch a
representation containing the output of the processing function. Use query
parameters to supply inputs to the processing function.
Run Code Online (Sandbox Code Playgroud)
对于输入很简单的情况(例如点的长/纬度坐标),这很明显.但是,我应该对图像等较大的输入采用相同的建议吗?据我所知,不可能将这么多数据作为查询参数发送.
我试图实现REST WCF以探索PUT和POST动词之间的区别.我已使用该服务在某个位置上传了一个文件.
服务实现如下:
[OperationContract]
[WebInvoke(UriTemplate = "/UploadFile", Method = "POST")]
void UploadFile(Stream fileContents);
public void UploadFile(Stream fileContents)
{
byte[] buffer = new byte[32768];
MemoryStream ms = new MemoryStream();
int bytesRead, totalBytesRead = 0;
do
{
bytesRead = fileContents.Read(buffer, 0, buffer.Length);
totalBytesRead += bytesRead;
ms.Write(buffer, 0, bytesRead);
} while (bytesRead > 0);
using (FileStream fs = File.OpenWrite(@"C:\temp\test.txt"))
{
ms.WriteTo(fs);
}
ms.Close();
Run Code Online (Sandbox Code Playgroud)
}
客户端代码如下:
HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create("http://localhost:1922 /EMPRESTService.svc/UploadFile");
request.Method = "POST";
request.ContentType = "text/plain";
byte[] fileToSend = File.ReadAllBytes(@"C:\TEMP\log.txt"); // txtFileName contains …Run Code Online (Sandbox Code Playgroud) 我的要求是使用前端作为 DOJO & Spring MVC 从 DB 中读取、更新、删除和插入数据。
我能够从数据库中获取记录并显示在 DOJO 增强网格(可编辑网格)中。在编辑网格数据时,我不知道如何将网格存储项发送到我的 Spring Controller 和数据库中的更新/插入/删除。
这是我尝试将数据从 java 控制器获取到前端的代码。
控制器类
@RequestMapping(value="eiaProjectSummary", produces = "application/json")
public @ResponseBody Map<String, Object> getEIAProjectSummary(
@RequestParam(required = true) String prodGroupId,
@RequestParam(required = true) List<Integer> eiaValues
) {
Map<String, Object> returnList = new HashMap<String, Object>();
List<PCPTAnalysisBean> pcptList = //getting the list of records from DB.
returnList.put("eiaProjSummaryList", pcptList);
return returnList;
}
Run Code Online (Sandbox Code Playgroud)
Javascript
dojo.xhrGet({
url: "pcptAnalysis/eiaProjectSummary.json?prodGroupId="+ prodGrpId +"&eiaValues="+eiaValues,
handleAs: "json",
preventCache: true,
load: function(response) {
var resultsGrid = new dojo.data.ItemFileReadStore({
data: …Run Code Online (Sandbox Code Playgroud) 假设我有:
@GET
public UserList fetch(@PathParam("user") String userId) {
// Do stuff here
}
Run Code Online (Sandbox Code Playgroud)
现在,假设我有自己的类型userId,我们称之为UserId。是否可以将其解析String为UserId将其传递到fetch方法中,即:
@GET
public UserList fetch(@PathParam("user") UserId userId) {
// Do stuff here
}
Run Code Online (Sandbox Code Playgroud)
我意识到一旦进入方法,我就可以解析字符串,但是我的方法获取我想要的类型会更方便。
POST:-用于创建和更新资源
PUT:-用于更新现有资源
我可以使用POST代替PUT方法吗?如果我使用POST方法而不是PUT方法,会有什么缺点?
如果POST可以执行PUT方法,为什么需要PUT方法?
该方法现在如下所示:
POST person/personId/edit
https://api.example.com/*key*/person/*personId*/edit?FName=Blah
Run Code Online (Sandbox Code Playgroud)
我希望将 personId 中人员的名字更改为 Blah。
如果我需要添加一个人,我会说:
PUT person/create
https://api.example.com/*key*/person/create
Run Code Online (Sandbox Code Playgroud)
它会添加一个具有新 personId 的人。
在API中,HTTP METHOD用于取消操作的内容。
我想这将不是一个DELETE请求,因为资源没有被处置。在这种情况下,应该是a POST还是a PUT?这是一些文档,但是我仍然不清楚它的区别:http : //www.w3.org/Protocols/rfc2616/rfc2616-sec9.html
我正在为电子商务风格的应用程序开发标准购物车。在购物车中,我们具有允许用户更新商品数量的标准流程。我了解如何使用标准的post方法来将信息传递到控制器中的操作上。我不知道动词PATCH和PUT。
如果我的控制器中有以下自定义操作(通过POST调用),那么使用标准操作(例如“更新”)的PATCH是否被认为更安全?我仍在学习有关Rails和PATCH和PUT的更多信息,这让我有些困惑。
carts_controller
def update_cart_qty
@item = Item.find(params[:line_item][:item_id])
quantity = params[:line_item][:quantity]
# if qty is a not a number or negative set to 1
quantity = '1' if !quantity.match(/^\d+$/)
if quantity == '0'
result = current_cart.line_items.where("item_id = ?", params[:line_item][:item_id]).destroy_all
respond_to do |format|
format.js {flash.now[:notice] = "Removed \"#{@item.title}\" from your cart."}
format.html {flash[:error] = "Removed \"#{@item.title}\" from your cart."}
end
else
result = current_cart.add_item_and_update(@item, quantity, branch, current_user, price)
current_cart.save
respond_to do |format|
format.js {flash.now[:notice] = "Qty \"#{quantity}\" …Run Code Online (Sandbox Code Playgroud) 我不知道 PATCH 和 PUT 方法之间的确切区别。谁能告诉我什么时候应该使用这种方法并举出适当的例子。
rest ×5
c# ×2
java ×2
post ×2
put ×2
api ×1
cocoa-touch ×1
database ×1
dojo ×1
dropwizard ×1
http ×1
iphone ×1
javascript ×1
jersey-2.0 ×1
laravel ×1
networking ×1
objective-c ×1
patch ×1
python ×1
spring-mvc ×1
wcf ×1
wcf-rest ×1