使用ngResource在AngularJS 1.2rc(X),我怎么现在得到了状态代码?
RestAPI.save({resource}, {data}, function( response, responseHeaders ) {
});
Run Code Online (Sandbox Code Playgroud)
哪里RestAPI是我的ngResource.
响应具有$promise从服务器返回的对象和资源,但不再具有状态.responseHeaders()如果服务器将状态代码注入头对象,但该函数仅返回真实的返回状态代码,则该函数仅具有状态.所以有些服务器可能会提供服务,而有些服
如何为Django响应添加响应头?我有:
response = HttpResponse()
response['Cache-Control'] = 'no-cache'
return render(request, "template.html", {})
# Alternately using render_to_response
# return render_to_response("template.html", {})
Run Code Online (Sandbox Code Playgroud) 我目前正在尝试将一些来自Android应用程序的数据发送到php服务器(两者都由我控制).
在应用程序中的表单上收集了大量数据,这些数据被写入数据库.这一切都有效.
在我的主要代码中,首先我创建了一个JSONObject(我在这里为此示例删除了它):
JSONObject j = new JSONObject();
j.put("engineer", "me");
j.put("date", "today");
j.put("fuel", "full");
j.put("car", "mine");
j.put("distance", "miles");
Run Code Online (Sandbox Code Playgroud)
接下来,我将对象传递给发送,并收到响应:
String url = "http://www.server.com/thisfile.php";
HttpResponse re = HTTPPoster.doPost(url, j);
String temp = EntityUtils.toString(re.getEntity());
if (temp.compareTo("SUCCESS")==0)
{
Toast.makeText(this, "Sending complete!", Toast.LENGTH_LONG).show();
}
Run Code Online (Sandbox Code Playgroud)
HTTPPoster类:
public static HttpResponse doPost(String url, JSONObject c) throws ClientProtocolException, IOException
{
HttpClient httpclient = new DefaultHttpClient();
HttpPost request = new HttpPost(url);
HttpEntity entity;
StringEntity s = new StringEntity(c.toString());
s.setContentEncoding(new BasicHeader(HTTP.CONTENT_TYPE, "application/json"));
entity = s;
request.setEntity(entity);
HttpResponse response;
response = …Run Code Online (Sandbox Code Playgroud) 我只是想澄清一下.
我知道,如果我在之前的请求中设置了cookie,它将显示在我的Request.Cookies收藏中.
我想更新现有的Cookie.
我的Request.Cookies收藏中的cookie是否已复制到我的Response.Cookies收藏中?我是否需要使用相同的密钥添加新的cookie Response.Cookies.Add(),或者我是否需要使用Response.Cookies.Set()?
asp.net httpresponse httprequest httpcookie httpcookiecollection
我有以下代码:
Image tmpimg = null;
HttpWebRequest httpWebRequest = (HttpWebRequest)HttpWebRequest.Create(url);
HttpWebResponse httpWebReponse = (HttpWebResponse)httpWebRequest.GetResponse();
Stream stream = httpWebReponse.GetResponseStream();
return Image.FromStream(stream);
Run Code Online (Sandbox Code Playgroud)
在我输入的最后一行Image.,FromStream不在列表中.我能做什么?
我想复制一个REST响应成团块,但我不能做一些,因为blob()和arrayBuffer()尚未响应对象已经实施.Response Body是一个私有变量.
...
return this.http.get(url, {params: params, headers: headers})
.map(res => {
// can't access _body because it is private
// no method appears to exist to get to the _body without modification
new Blob([res._body], {type: res.headers.get('Content-Type')});
})
.catch(this.log);
...
Run Code Online (Sandbox Code Playgroud)
在实施这些方法之前,我是否可以使用解决方案?
正如我们所知,Apache HTTP Client已在API 23中删除
但是,Volley库目前仍然使用Apache的库如
import org.apache.http.Header;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.HttpStatus;
import org.apache.http.StatusLine;
import org.apache.http.conn.ConnectTimeoutException;
import org.apache.http.impl.cookie.DateUtils;
Run Code Online (Sandbox Code Playgroud)
我测试了2个项目:一个用于compileSdkVersion 22,另一个用于compileSdkVersion 23获得2个截图:
compileSdkVersion 22
compileSdkVersion 23
我有两个问题:
Apache在运行时使用该库,他们是在API22或更低版本中找到的?Apache图书馆吗?如果没有,当Apache我的图书馆完全删除并且不受支持时,我现在的项目是否仍会继续使用?也许我的英语不太清楚,但希望你能理解我的问题.
任何解释将不胜感激.
更新:
从@ random的评论中,我使用谷歌的官方Volley库创建了一个新的API23项目(我的意思git clone https://android.googlesource.com/platform/frameworks/volley是谷歌建议的这里),而不是compile 'com.mcxiaoke.volley:library:1.0.17'在build.gradle文件中使用.是的,在构建项目时因缺少Apache库而出错.必须按文档添加useLibrary 'org.apache.http.legacy'到build.gradle文件中.
第二次更新:
我刚刚定制了谷歌的排球(作为我项目中的一个模块),删除了Apache库.请转到我的GitHub示例项目供您参考.但请注意,它尚未针对所有情况进行全面测试,并且我仅测试了02个简单案例:GET并且POST我的Web服务请求是ASP.NET Web …
apache android httpresponse android-volley android-api-levels
我有一个控制器方法来处理ajax调用并返回JSON.我正在使用json.org的JSON库来创建JSON.
我可以做以下事情:
@RequestMapping(method = RequestMethod.POST)
@ResponseBody
public String getJson()
{
JSONObject rootJson = new JSONObject();
// Populate JSON
return rootJson.toString();
}
Run Code Online (Sandbox Code Playgroud)
但是将JSON字符串放在一起是有效的,只是让Spring将它写入响应的输出流.
相反,我可以将它直接写入响应输出流,如下所示:
@RequestMapping(method = RequestMethod.POST)
public void getJson(HttpServletResponse response)
{
JSONObject rootJson = new JSONObject();
// Populate JSON
rootJson.write(response.getWriter());
}
Run Code Online (Sandbox Code Playgroud)
但似乎有一个更好的方法来做到这一点,而不是诉诸于传递HttpServletResponse给处理程序方法.
是否有另一个类或接口可以从我可以使用的处理程序方法返回,以及@ResponseBody注释?
我写了一个简单的httprequest /响应代码,我得到以下错误.我在类路径中引用了httpclient,httpcore,common-codecs和common-logging.我是java的新手,不知道这里发生了什么.请帮我.
码:
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.HttpResponse;
import org.apache.http.impl.client.HttpClientBuilder;
import org.apache.http.Header;
import org.apache.http.HttpHeaders;
public class UnshorteningUrl {
public static void main(String[] args) throws Exception
{
HttpGet request=null;
HttpClient client = HttpClientBuilder.create().build();
try {
request = new HttpGet("trib.me/1lBFzSi");
HttpResponse httpResponse=client.execute(request);
Header[] headers = httpResponse.getHeaders(HttpHeaders.LOCATION);
// Preconditions.checkState(headers.length == 1);
String newUrl = headers[0].getValue();
System.out.println("new url" + newUrl);
} catch (IllegalArgumentException e) {
// TODO: handle exception
}finally {
if (request != null) {
request.releaseConnection();
}
}
}}
Run Code Online (Sandbox Code Playgroud)
错误:
Exception in …Run Code Online (Sandbox Code Playgroud) 在web api 2中,我们习惯于使用字符串内容来获取响应:
var response = Request.CreateResponse(HttpStatusCode.Ok);
response.Content = new StringContent("<my json result>", Encoding.UTF8, "application/json");
Run Code Online (Sandbox Code Playgroud)
如何在不使用像ObjectResult这样的内置类的情况下在ASP.NET 5/MVC 6中实现相同的功能?
httpresponse ×10
android ×2
c# ×2
httpclient ×2
angular ×1
angularjs ×1
apache ×1
asp.net ×1
blob ×1
django ×1
http-request ×1
httpcookie ×1
httprequest ×1
java ×1
json ×1
php ×1
rest ×1
spring ×1
spring-mvc ×1