---
title: "CURL"
author: "hangzhoujava"
date: "2016-01-18T11:21:29Z"
tags: []
categories: ["Web前端"]
slug: "curl"
draft: false
lastmod: "2016-01-18T11:53:20Z"
id: 2271740
url: "https://hangzhoujava.iteye.com/blog/2271740"
---

模拟POST请求有几种方式

1 HTTPCLIENT

```
JSONObject jsonObj = new JSONObject();
jsonObj.put("username", username);
jsonObj.put("apikey", apikey);
// Create the POST object and add the parameters
HttpPost httpPost = new HttpPost(url);
StringEntity entity = new StringEntity(jsonObj.toString(), HTTP.UTF_8);
entity.setContentType("application/json");
httpPost.setEntity(entity);
HttpClient client = new DefaultHttpClient();
HttpResponse response = client.execute(httpPost);
```

 

2 CURL 

发现CURL还是极其舒服的，比如一个JSON的POST请求，可以这么写

```
curl -l -H "Content-type: application/json" -X POST -d '{"phone":"13521389587","password":"test"}' http://domain/apis/users.json
```

 3 JS Ajax