# 8.1.与服务器通讯

## Http通讯

了解angular的Http服务 发送http请求 处理http响应

url method header

httpModule

```typescript
dataSource:Observable<any>;

products:Array<any>=[];

construction(private http:Http){
let myHeaders：Headers=new Headers();
myHeaders:append("Authorization","Basic 123456")
    this.dataSource=this.http.get('/products',{headers:myHeaders})
    .map((res)=>res.json());
}

this.dataSource.subscribe(
(data)=>{
    this.products=res.json
})
```

proxy.conf.json

```javascript
{
    "/api":{
        "target":"http://localhost:8000"
    }
}
```

package.json

```javascript
"start":"ng serve --proxy-config proxy.conf.json"
```

使用 | async 管道 可以代替订阅


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://moluo.gitbook.io/notes/bian-cheng-xue-xi/qian-duan/angular/8.1.-yu-fu-wu-qi-tong-xun.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
