为什么JS没有类似HttpClient类似纹身的东西叫什么

node.js+Android(使用HttpURLConnection和HttpClient)实现文件上传_Linux编程_Linux公社-Linux系统门户网站
你好,游客
node.js+Android(使用HttpURLConnection和HttpClient)实现文件上传
来源:Linux社区&
作者:dead-horse
这篇node.js 第三方模块如何安装(使用npm)及介绍& 了formidable的安装(见),这一篇结合写一个文件上传的例子。
先上服务端node.js 的代码,保存为upload.js
[javascript]
var&http&=&require('http');&&
var&fs&=&require('fs');&&
var&formidable&=&require('formidable');&&
var&firstPage&=&function(res){&&
&&&&res.writeHead(200,&{'Content-Type':&'text/html'});&&
&&&&var&html&=&fs.readFileSync(__dirname&+&'/public/form.html');&&
&&&&res.end(html);&&
var&resultPage&=&function(res,data,files){&&
&&&&res.setHeader('Content-Type',&'text/html');&&
&&&&res.write('&p&thanks&'&+&data.name&+&'&/p&');&&
&&&&res.write('&ul&');&&
&&&&console.log(data);&&
&&&&console.log(files);&&
&&&&if&(Array.isArray(files.images))&{&&
&&&&&&files.images.forEach(function(image){&&
&&&&&&&&var&kb&=&image.size&/&1024&|&0;&&
&&&&&&&&res.write('&li&uploaded&'&+&image.name&+&'&'&+&kb&+&'kb&/li&');&&
&&&&&&});&&
&&&&}&else&{&&
&&&&&&var&image&=&files.&&
&&&&&&var&kb&=&image.size&/&1024&|&0;&&
&&&&&&res.write('&li&uploaded&'&+&image.name&+&'&'&+&kb&+&'kb&/li&');&&
&&&&res.end('&/ul&');&&
var&server&=&http.createServer(function(req,&res)&{&&
&&&&if&(req.method&==&'GET'){&&
&&&&&&&&return&firstPage(res);&&
&&&&var&form&=&new&formidable.IncomingF&&
&&&&var&data&=&{};&&
&&&&var&files&=&{};&&
&&&&form.uploadDir&=&__dirname&+'/file';&&
&&&&form.keepExtensions&=&true;&&
&&&&function&ondata(name,&val,&data){&&
&&&&&&&&if&(Array.isArray(data[name]))&{&&
&&&&&&&&&&&&data[name].push(val);&&
&&&&&&&&}&else&if&(data[name])&{&&
&&&&&&&&&&&&data[name]&=&[data[name],&val];&&
&&&&&&&&}&else&{&&
&&&&&&&&&&&&data[name]&=&&&
&&&&&&&&}&&
&&&&form.on('field',&function(name,&val){&&
&&&&&&&&ondata(name,&val,&data);&&
&&&&form.on('file',&function(name,&val){&&
&&&&&&&&ondata(name,&val,&files);&&
&&&&form.on('end',&function()&{&&
&&&&&&&&resultPage(res,data,files);&&&
&&&&form.parse(req);&&
server.listen(8080);&&
console.log('listening&on&http://localhost:8080');&&__dirname + '/public/form.html,在js当前目录下建立public文件夹,文件夹下建立form.html文件,文件内容如下
&&&&&&&&&action="/"&method="post"&enctype="multipart/form-data"&&
&&&&&&&&&&&type="text"&name="name"&placeholder="Name:"&&&
&&&&&&&&&&&type="file"&name="images"&multiple="multiple"&&&
&&&&&&&&&&&type="submit"&value="Upload"&&&
&&&&&&&&&&
代码比较简单,formidable部分可以上官网看API。
运行以下看看
在浏览器中打开http://localhost:8080
选择文件,输入文件name
点击upload
文件上传成功
再看android代码,布局文件main.xml如下
&version="1.0"&encoding="utf-8"&&
&xmlns:android="http://schemas.android.com/apk/res/android"&&
&&&&android:id="@+id/RelativeLayout1"&&
&&&&android:layout_width="fill_parent"&&
&&&&android:layout_height="fill_parent"&&
&&&&android:orientation="vertical"&&&
&&&&&&&&android:id="@+id/textViewInfo"&&
&&&&&&&&android:layout_width="fill_parent"&&
&&&&&&&&android:layout_height="wrap_content"&&
&&&&&&&&android:layout_alignParentLeft="true"&&
&&&&&&&&android:layout_alignParentTop="true"&&
&&&&&&&&&&
&&&&&&&&android:id="@+id/textView1"&&
&&&&&&&&android:layout_width="wrap_content"&&
&&&&&&&&android:layout_height="wrap_content"&&
&&&&&&&&android:layout_alignParentLeft="true"&&
&&&&&&&&android:layout_below="@+id/textViewInfo"&&
&&&&&&&&android:layout_marginLeft="40dp"&&
&&&&&&&&android:layout_marginTop="20dp"&&
&&&&&&&&android:text="文件路径"&&&
&&&&&&&&android:textAppearance="?android:attr/textAppearanceMedium"&&&
&&&&&&&&android:id="@+id/textViewFile"&&
&&&&&&&&android:layout_width="wrap_content"&&
&&&&&&&&android:layout_height="wrap_content"&&
&&&&&&&&android:layout_alignLeft="@+id/textView1"&&
&&&&&&&&android:layout_below="@+id/textView1"&&
&&&&&&&&android:id="@+id/textView3"&&
&&&&&&&&android:layout_width="wrap_content"&&
&&&&&&&&android:layout_height="wrap_content"&&
&&&&&&&&android:layout_alignLeft="@+id/textViewFile"&&
&&&&&&&&android:layout_below="@+id/textViewFile"&&
&&&&&&&&android:layout_marginTop="10dp"&&
&&&&&&&&android:text="上传网址"&&&
&&&&&&&&android:textAppearance="?android:attr/textAppearanceMedium"&&&
&&&&&&&&android:id="@+id/textViewUrl"&&
&&&&&&&&android:layout_width="wrap_content"&&
&&&&&&&&android:layout_height="wrap_content"&&
&&&&&&&&android:layout_alignLeft="@+id/textView3"&&
&&&&&&&&android:layout_below="@+id/textView3"&&
&&&&&&&&android:id="@+id/webViewResult"&&
&&&&&&&&android:layout_width="fill_parent"&&
&&&&&&&&android:layout_height="100dp"&&
&&&&&&&&android:layout_below="@+id/textViewUrl"&&
&&&&&&&&android:layout_marginTop="30dp"&&
&&&&&&&&android:id="@+id/buttonJava"&&
&&&&&&&&android:layout_width="wrap_content"&&
&&&&&&&&android:layout_height="wrap_content"&&
&&&&&&&&android:layout_alignParentBottom="true"&&
&&&&&&&&android:layout_marginLeft="60dp"&&
&&&&&&&&android:text="Java上传"&&&
&&&&&&&&android:id="@+id/buttonApache"&&
&&&&&&&&android:layout_width="wrap_content"&&
&&&&&&&&android:layout_height="wrap_content"&&
&&&&&&&&android:layout_alignBottom="@+id/buttonJava"&&
&&&&&&&&android:layout_toRightOf="@+id/buttonJava"&&
&&&&&&&&android:text="Apache上传"&&&
相关资讯 & & &
& (11/20/:04)
& (08/25/:33)
& (03月23日)
& (11/06/:26)
& (08/03/:57)
   同意评论声明
   发表
尊重网上道德,遵守中华人民共和国的各项有关法律法规
承担一切因您的行为而直接或间接导致的民事或刑事法律责任
本站管理人员有权保留或删除其管辖留言中的任意内容
本站有权在网站内转载或引用您的评论
参与本评论即表明您已经阅读并接受上述条款httpClient怎样获取网页中js执行完后的网页源码
[问题点数:20分,结帖人michael2988]
本版专家分:0
结帖率 100%
CSDN今日推荐
本版专家分:544
本版专家分:0
本版专家分:541
本版专家分:20
本版专家分:27366
2010年12月 Java大版内专家分月排行榜第一
2011年1月 Java大版内专家分月排行榜第二
本版专家分:22
本版专家分:20
本版专家分:20
本版专家分:270
本版专家分:0
本版专家分:0
本版专家分:0
本版专家分:0
本版专家分:0
本版专家分:0
本版专家分:549
本版专家分:5
本版专家分:87
匿名用户不能发表回复!
其他相关推荐求助:如何析取异步加载的html信息,获取多次请求后的完整html页面,jsoup,httpclient,httpunit都有人说可都没法实现
[问题点数:20分,结帖人Jeffreyjingsi]
本版专家分:0
结帖率 100%
CSDN今日推荐
本版专家分:0
本版专家分:0
本版专家分:0
本版专家分:0
本版专家分:13608
2013年10月 其他开发语言大版内专家分月排行榜第一
2013年9月 其他开发语言大版内专家分月排行榜第二2013年8月 其他开发语言大版内专家分月排行榜第二2013年7月 其他开发语言大版内专家分月排行榜第二2011年4月 PHP大版内专家分月排行榜第二
2013年10月 PHP大版内专家分月排行榜第三2013年5月 PHP大版内专家分月排行榜第三2013年4月 其他开发语言大版内专家分月排行榜第三2013年4月 PHP大版内专家分月排行榜第三2013年3月 其他开发语言大版内专家分月排行榜第三2011年5月 PHP大版内专家分月排行榜第三
本版专家分:0
本版专家分:0
本版专家分:0
本版专家分:0
匿名用户不能发表回复!
其他相关推荐文章 - 1&评论 - 0&trackbacks - 0
& & & 目前C/S还是B/S结构的应用程序, HTTP 应该是最为广泛使用的协议了。在 Java 平台上,Java 标准库提供了 一个HttpURLConnection 类来支持 HTTP 通讯。不过 HttpURLConnection 本身的 API 不够友好,所提供的功能也有限。httpClien是一个实现http协议很多操作功能的组件,并且它支持 HTTP 协议最新的版本和建议,现在Android已经成功的集成了HttpClient。另外,最新由Square 公司开源的 OkHttp 据说能提供更高效率的http连接,支持GZIP 压缩和 HTTP 响应缓存功能,在原理上应该是大同小异的。
& & & 再说httpclient ,那也是眼花缭乱。随便一搜,比如有些博文使用了&org.apache.commons.httpclient.HttpClient ,有些博文用org.apache.http.client.HttpClient 类。原来,httpclient本来是属于apache-commons 项目下的一个子项目,后来是由Apache&HttpComponents项目开发了后面的版本以提供更好的性能和更大的灵活性。commons下的这个httpclient最高版本是目前的3.1,支持HTTP协议1.1,继承了java.net.urlConnection,已经足够提供目前测试的大部分rest服务接口,本文介绍一下用法。这里可以查看所有的API -&&&
&  在金融产品的测试过程中,我曾经碰到的服务接口有区分,比如与合作方交互一般是传xml较多,单应用的后台一般是http rest服务。这里提供一个传json的例子。
public void urlPostJson(String url,String desc,String json) {
log.info("-----------------------------"+desc+"
Request: " + json);
HttpClient client = new HttpClient();
client.getHostConfiguration().setProxy("127.0.0.1", 5689);
client.getHttpConnectionManager().getParams().setConnectionTimeout(3000);//
client.setConnectionTimeout(3000);
client.getParams().setSoTimeout(3000);//
client.setTimeout(1000);
client.getParams().setConnectionManagerTimeout(1000);
PostMethod method = new PostMethod(url);
method.setRequestHeader("Content-Type", " application/ charset=UTF-8");
method.setRequestBody(new ByteArrayInputStream(json.getBytes("UTF-8")));
method.setRequestBody(json);
int status = client.executeMethod(method);
String res=method.getResponseBodyAsString();
log.info("
status:"+status+"
Resonse: "+res);
} catch (IOException e) {
log.error("HttpClient.executeMethod(postMethod) IOException!",e);
if (method != null) {
method.releaseConnection();
如上,利用httpclient去访问接口的步骤一般是:
1. 创建HttpClient对象。2. 构造Http 请求对象。3. 执行HttpClient对象的execute方法,将Http请求对象作为该方法的参数。4. 读取execute方法返回的HttpResponse结果并解析。5、释放连接。整个过程是不是与我们平时在浏览器上访问类似呢。唯一区别是不能执行HTTP页面中签入嵌入的JS代码,自然也不会对页面内容进行任何解析、处理,这些都是需要开发人员来完成的。在以上代码中,httpclient的初始化没有看到任何参数设置,其实是在它的构造函数里调用了接口,并设置了默认值,如下包含协议版本、客户端引擎、cookie策略等,如果要自己设置,可以通过它的成员变量httpClientParams对象进行设置。
1、关于重定向。
&http多种状态已经在HttpStatus这个类中定义好,其中重定向 根据RFC2616中对自动转向的定义,主要有两种:301和302。301表示永久的移走(Moved Permanently),当返回的是301,则表示请求的资源已经被移到一个固定的新地方,任何向该地址发起请求都会被转到新的地址上。302表示暂时的转向,比如在服务器端的servlet程序调用了sendRedirect方法,则在客户端就会得到一个302的代码,这时服务器返回的头信息中location的值就是sendRedirect转向的目标地址。如果是get方式请求,httpclient是自动帮你重定向并拿到响应信息,也可以通过设置method.setFollowRedirects(false)不自动转。post的请求是不能自动跳转的,需要从头部信息中拿到Location(可能是相对路径)因此需要对location返回的值做一些处理才可以发起向新地址的请求。
2、字符编码
客户端发送的数据多样,最终所有数据都是通过最底层的物理层面的电信号来传递,首部字段content-type 说明了实体主体内对象的媒体类型,即服务器通过contentType来知道这个是什么样子的数据。客户端在拿到服务器返回的数据后,根据头部设置的可接收媒体类型进行内容协商,返回最适合的资源。对于有中文的请求,为避免出现乱码,最好设置content-type。在上部分的代码截图,大家可以看到,如果我们自己不设置contentType 那么默认会采用ISO的方式进行传输,那么如果与你实际的编码方式不一致的话,服务器就会拿到一个乱码,从而无法正常的响应。可以通过上面代码进行设置,也可以通过method.setRequestHeader("Content-Type", " application/json; charset=UTF-8")来进行设置
httpclient默认的cookie策略是RFC_2109其中可以通过去更改。请求过程中可以通过sendHead 把cookie放入头部,并传到后端进行访问。
基本上使用httpclient过程中,主要操作的类有:httpclient,getMethod,postMethod,httpClientParams,httpConnectionManager这几个。详见以下的类图。
&HttpClient代表了一个http的客户端,HttpConnectionManager是用来管理HttpConnection 的,HttpConnection代表了一个http连接,所以HttpConnectionManager其实质上也就是一个http连接池,管理这些 http连接(和数据库连接池一个道理)。HttpMethod代表了一个Http方法,一个HttpClient可以运行多个HttpMethod(实 质上,httpclient执行一个HttpMethod时,会从connectionmanager那里获取一个httpconnection,在此 connection上执行该method,执行完该method后,让method 释放该httpconnection,从而将该httpconnection返回给connectionmanager,以便供后续的method使 用)所以在httpclient连接后资源释放问题很重要,就跟我们用database connection要释放资源一样。&
1、fidder作为一款强大好用的web调试利器,针对commons下的httpclient可以如下设置代理,能帮你记录下请求和响应的所有信息。 接口测试中遇到异常方便查看,减少自己debug的情况。
httpclient功能之强大,不是一篇文章能够说完。其他的,例如文件上传、DNS配置、多线程下的httpclient使用。过程中需要你对http协议、cookie-session机制有一定的认识基础。本篇文件旨在用做一些简单接口的测试,目前commons这个版本已经不做更新了,如果有更复杂的接口,还是推荐使用org.apache.http.impl.client下的httpclient。
阅读(...) 评论()37.5k 次阅读
这篇文章已经介绍过 HttpClient ,今天看到 angular-university 博客中介绍 HttpClient 的文章,内容很详细,我就简单做了整理。有兴趣的话,建议直接阅读 。
HttpClientModule 应用
导入新的 HTTP Module
import {HttpClientModule} from '@angular/common/http';
@NgModule({
declarations: [
AppComponent
imports: [
BrowserModule,
HttpClientModule
providers: [],
bootstrap: [AppComponent]
export class AppModule {}
需要注意的是,现在 JSON 是默认的数据格式,我们不需要再进行显式的解析。即我们不需要再使用以下代码:
http.get(url).map(res =& res.json()).subscribe(...)
现在我们可以这样写:
http.get(url).subscribe(...)
发送 Get 请求
import {Component, OnInit} from '@angular/core';
import {Observable} from "rxjs/Observable";
import {HttpClient} from "@angular/common/http";
import * as _ from 'lodash';
interface Course {
description:
courseListIcon:
longDescription:
@Component({
selector: 'app-root',
template: `
&ul *ngIf="courses$ | async as courses else noData"&
&li *ngFor="let course of courses"&
{{course.description}}
&ng-template #noData&No Data Available&/ng-template&
export class AppComponent implements OnInit {
courses$: Observable&any&;
constructor(private http:HttpClient) {}
ngOnInit() {
this.courses$ = this.http
.get("https://angular-http-guide.firebaseio.com/courses.json")
.map(data =& _.values(data))
.do(console.log);
设置查询参数
假设发送 Get 请求时,需要设置对应的查询参数,预期的 URL 地址如下:
https://angular-http-guide.firebaseio.com/courses.json?orderBy="$key"&limitToFirst=1
创建 HttpParams 对象
import {HttpParams} from "@angular/common/http";
const params = new HttpParams()
.set('orderBy', '"$key"')
.set('limitToFirst', "1");
this.courses$ = this.http
.get("/courses.json", {params})
.do(console.log)
.map(data =& _.values(data))
需要注意的是,我们通过链式语法调用 set() 方法,构建 HttpParams 对象。这是因为 HttpParams 对象是不可变的,通过 set() 方法可以防止该对象被修改。
每当调用 set() 方法,将会返回包含新值的 HttpParams 对象,因此如果使用下面的方式,将不能正确的设置参数。
const params = new HttpParams();
params.set('orderBy', '"$key"')
params.set('limitToFirst', "1");
使用 fromString 语法
const params = new HttpParams({fromString: 'orderBy="$key"&limitToFirst=1'});
使用 request() API
const params = new HttpParams({fromString: 'orderBy="$key"&limitToFirst=1'});
this.courses$ = this.http
"/courses.json",
responseType:"json",
.do(console.log)
.map(data =& _.values(data));
设置 HTTP Headers
const headers = new HttpHeaders().set("X-CustomHeader", "custom header value");
this.courses$ = this.http
"/courses.json",
{headers})
.do(console.log)
.map(data =& _.values(data));
发送 Put 请求
httpPutExample() {
const headers = new HttpHeaders().set("Content-Type", "application/json");
this.http.put("/courses/-KgVwECOnlc-LHb_B0cQ.json",
"courseListIcon": ".../main-page-logo-small-hat.png",
"description": "Angular Tutorial For Beginners TEST",
"iconUrl": ".../angular2-for-beginners.jpg",
"longDescription": "...",
"url": "new-value-for-url"
{headers})
.subscribe(
console.log("PUT call successful value returned in body",
response =& {
console.log("PUT call in error", response);
console.log("The PUT observable is now completed.");
发送 Patch 请求
httpPatchExample() {
this.http.patch("/courses/-KgVwECOnlc-LHb_B0cQ.json",
"description": "Angular Tutorial For Beginners PATCH TEST",
.subscribe(
(val) =& {
console.log("PATCH call successful value returned in body",
response =& {
console.log("PATCH call in error", response);
console.log("The PATCH observable is now completed.");
发送 Delete 请求
httpDeleteExample() {
this.http.delete("/courses/-KgVwECOnlc-LHb_B0cQ.json")
.subscribe(
(val) =& {
console.log("DELETE call successful value returned in body",
response =& {
console.log("DELETE call in error", response);
console.log("The DELETE observable is now completed.");
发送 Post 请求
httpPostExample() {
this.http.post("/courses/-KgVwECOnlc-LHb_B0cQ.json",
"courseListIcon": "...",
"description": "TEST",
"iconUrl": "..",
"longDescription": "...",
"url": "new-url"
.subscribe(
(val) =& {
console.log("POST call successful value returned in body",
response =& {
console.log("POST call in error", response);
console.log("The POST observable is now completed.");
避免重复请求
duplicateRequestsExample() {
const httpGet$ = this.http
.get("/courses.json")
.map(data =& _.values(data));
httpGet$.subscribe(
(val) =& console.log("logging GET value", val)
this.courses$ = httpGet$;
在上面例子中,我们正在创建了一个 HTTP observable 对象 httpGet$,接着我们直接订阅该对象。然后,我们把 httpGet$ 对象赋值给 courses$ 成员变量,最后在模板中使用 async 管道订阅该对象。
这将导致发送两个 HTTP 请求,在这种情况下,请求显然是重复的,因为我们只希望从后端查询一次数据。为了避免发送冗余的请求,我们可以使用 RxJS 提供的 shareReplay 操作符:
// put this next to the other RxJs operator imports
import 'rxjs/add/operator/shareReplay';
const httpGet$ = this.http
.get("/courses.json")
.map(data =& _.values(data))
.shareReplay();
并行发送多个请求
并行发送 HTTP 请求的一种方法是使用 RxJs 中的 forkjoin 操作符:
import 'rxjs/add/observable/forkJoin';
parallelRequests() {
const parallel$ = Observable.forkJoin(
this.http.get('/courses/-KgVwEBq5wbFnjj7O8Fp.json'),
this.http.get('/courses/-KgVwECOnlc-LHb_B0cQ.json')
parallel$.subscribe(
values =& {
console.log("all values", values)
顺序发送 Http 请求
sequentialRequests() {
const sequence$ = this.http.get&Course&('/courses/-KgVwEBq5wbFnjj7O8Fp.json')
.switchMap(course =& {
course.description+= ' - TEST ';
return this.http.put('/courses/-KgVwEBq5wbFnjj7O8Fp.json', course)
sequence$.subscribe();
获取顺序发送 Http 请求的结果
sequentialRequests() {
const sequence$ = this.http.get&Course&('/courses/-KgVwEBq5wbFnjj7O8Fp.json')
.switchMap(course =& {
course.description+= ' - TEST ';
return this.http.put('/courses/-KgVwEBq5wbFnjj7O8Fp.json', course)
(firstHTTPResult, secondHTTPResult)
=& [firstHTTPResult, secondHTTPResult]);
sequence$.subscribe(values =& console.log("result observable ", values) );
请求异常处理
throwError() {
.get("/api/simulate-error")
.catch( error =& {
// here we can show an error message to the user,
// for example via a service
console.error("error catched", error);
return Observable.of({description: "Error Value Emitted"});
.subscribe(
val =& console.log('Value emitted successfully', val),
error =& {
console.error("This line is never called ",error);
() =& console.log("HTTP Observable completed...")
当发生异常时,控制台的输出结果:
Error catched
HttpErrorResponse {headers: HttpHeaders, status: 404, statusText: "Not Found", url: "http://localhost:4200/api/simulate-error", ok: false, … }
Value emitted successfully {description: "Error Value Emitted"}
HTTP Observable completed...
Http 拦截器
定义拦截器
import {Injectable} from "@angular/core";
import {HttpEvent, HttpHandler, HttpInterceptor} from "@angular/common/http";
import {HttpRequest} from "@angular/common/http";
import {Observable} from "rxjs/Observable";
@Injectable()
export class AuthInterceptor implements HttpInterceptor {
constructor(private authService: AuthService) {
intercept(req: HttpRequest&any&, next: HttpHandler): Observable&HttpEvent&any&& {
const clonedRequest = req.clone({
headers: req.headers.set('X-CustomAuthHeader', authService.getToken())
console.log("new headers", clonedRequest.headers.keys());
return next.handle(clonedRequest);
配置拦截器
@NgModule({
declarations: [
AppComponent
imports: [
BrowserModule,
HttpClientModule
providers: [
[ { provide: HTTP_INTERCEPTORS, useClass: AuthInterceptor, multi: true } ]
bootstrap: [AppComponent]
export class AppModule { }
Http 进度事件
longRequest() {
const request = new HttpRequest(
"POST", "/api/test-request", {},
{reportProgress: true});
this.http.request(request)
.subscribe(
event =& {
if (event.type === HttpEventType.DownloadProgress) {
console.log("Download progress event", event);
if (event.type === HttpEventType.UploadProgress) {
console.log("Upload progress event", event);
if (event.type === HttpEventType.Response) {
console.log("response received...", event.body);
上面示例运行后,控制台的可能的输出结果:
Upload progress event Object {type: 1, loaded: 2, total: 2}
Download progress event Object {type: 3, loaded: 31, total: 31}
Response Received... Object {description: "POST Response"}
40 收藏&&|&&79
最近用4.3.1的版本后,发现一个问题之前版本中http.get()可以访问的接口,突然控制台都输出404。而使用新的httpClient.get()则可以访问。有趣的是,这时候使用httpClient.get()访问内存中的数据即“api/xxxxx”的时候又是404,而用http.get()则可以。我想问的是官方现在是把Http和HttpClient这2个模块做了拆分了吗?
最近用4.3.1的版本后,发现一个问题
之前版本中http.get()可以访问的接口,突然控制台都输出404。而使用新的httpClient.get()则可以访问。有趣的是,这时候使用httpClient.get()访问内存中的数据即“api/xxxxx”的时候又是404,而用http.get()则可以。我想问的是官方现在是把Http和HttpClient这2个模块做了拆分了吗?
速度杠杠滴
速度杠杠滴
注册了拦截器之后 不知道该如何使用,可否指导一下
注册了拦截器之后 不知道该如何使用,可否指导一下
http://codingthesmartway.com/angular-4-3-httpclient-accessing-rest-web-services-with-angular/
请问代码作者自己编译通过了吗?
请问代码作者自己编译通过了吗?
同问,试了几个都不对
同问,试了几个都不对
any comments for "how to using HttpClient with FormData" ?
any comments for &how to using HttpClient with FormData& ?
post 传中文乱码怎么办?
post 传中文乱码怎么办?
顺序发送 Http 请求: 不是switchMap 而是mergeMap...
顺序发送 Http 请求: 不是switchMap 而是mergeMap...
楼主,拦截器是启动了,但是效果不理想,拦截器里的set方法并没有设置成功headers里的一个参数和值,
楼主,拦截器是启动了,但是效果不理想,拦截器里的set方法并没有设置成功headers里的一个参数和值,
请问。HTTPClient可以做单向或者是双向认证吗
请问。HTTPClient可以做单向或者是双向认证吗
HTTPClient不是说不需要map了吗,这是和Http的区别吧
HTTPClient不是说不需要map了吗,这是和Http的区别吧
是responseType默认是JSON,而不需要在使用 res.json() 执行反序列化。
是responseType默认是JSON,而不需要在使用 res.json() 执行反序列化。
分享到微博?
我要该,理由是:
在 SegmentFault,学习技能、解决问题
每个月,我们帮助 1000 万的开发者解决各种各样的技术问题。并助力他们在技术能力、职业生涯、影响力上获得提升。

我要回帖

更多关于 类似鸡眼的东西 的文章

 

随机推荐