-
Notifications
You must be signed in to change notification settings - Fork 153
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
更新 "在 Fragment 中使用"请求的服务器改为自建服务器,速度比雅虎财经的服务器快些
- Loading branch information
Showing
16 changed files
with
395 additions
and
272 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
95 changes: 95 additions & 0 deletions
95
app/src/main/java/com/wordplat/quickstart/bean/request/ServerRequestParams.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
package com.wordplat.quickstart.bean.request; | ||
|
||
import android.text.TextUtils; | ||
import android.util.Log; | ||
|
||
import com.alibaba.fastjson.JSONObject; | ||
import com.wordplat.quickstart.BuildConfig; | ||
|
||
import org.xutils.http.RequestParams; | ||
|
||
import java.io.File; | ||
|
||
/** | ||
* <p>ServerRequestParams</p> | ||
* <p>Date: 2017/4/5</p> | ||
* | ||
* @author afon | ||
*/ | ||
|
||
public class ServerRequestParams extends RequestParams { | ||
private static final String TAG = "ServerRequestParams"; | ||
|
||
private JSONObject params = null; | ||
|
||
private JSONObject requestJson= null; | ||
|
||
private String uploadKey = null; | ||
private Object uploadValue = null; | ||
|
||
public ServerRequestParams(String URL) { | ||
super(URL); | ||
params = new JSONObject(); | ||
|
||
requestJson = new JSONObject(); | ||
} | ||
|
||
public void addRequestParams(String key, Object value) { | ||
if (TextUtils.isEmpty(key) || value == null) { | ||
return; | ||
} | ||
|
||
requestJson.put(key, value); | ||
} | ||
|
||
public void addCustomParams(String key, JSONObject jsonObject) { | ||
if (TextUtils.isEmpty(key) || jsonObject == null) { | ||
return; | ||
} | ||
|
||
params.put(key, jsonObject); | ||
} | ||
|
||
/** | ||
* 上传文件 | ||
* | ||
* @param value 可以是File, InputStream 或 byte[] | ||
*/ | ||
public void upload(Object value) { | ||
uploadKey = "uploadFile"; | ||
uploadValue = value; | ||
} | ||
|
||
/** | ||
* 添加完参数或设置参数后调用此方法 | ||
*/ | ||
public void commit() { | ||
params.put("RequestParams", requestJson); | ||
|
||
if (BuildConfig.DEBUG) { | ||
Log.i(TAG, "##d 请求数据: " + requestJson.toJSONString()); | ||
} | ||
|
||
addBodyParameter("", requestJson.toJSONString()); | ||
|
||
if (!TextUtils.isEmpty(uploadKey) && uploadValue != null) { | ||
if (uploadValue instanceof org.json.JSONArray) { | ||
addParameter(uploadKey, uploadValue); | ||
|
||
} else if(uploadValue instanceof String) { | ||
addBodyParameter(uploadKey, new File((String) uploadValue)); | ||
|
||
} else if(uploadValue instanceof File) { | ||
addBodyParameter(uploadKey, (File)uploadValue); | ||
|
||
} else { | ||
addBodyParameter(uploadKey, uploadValue, "image/jpeg", System.currentTimeMillis()+".jpg"); | ||
} | ||
} | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return params.toJSONString(); | ||
} | ||
} |
28 changes: 0 additions & 28 deletions
28
app/src/main/java/com/wordplat/quickstart/bean/response/YahooResponse.java
This file was deleted.
Oops, something went wrong.
63 changes: 0 additions & 63 deletions
63
app/src/main/java/com/wordplat/quickstart/bean/response/YahooResponseParser.java
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.