- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我正在尝试通过 POST 将 json obj 通过 volley 在我的 android 应用程序中发送到 api 并捕获 json 响应,但我不断收到此错误: E/Volley:[194] BasicNetwork.performRequest:http://phoneapi.adro.co/Services/AdService.svc/GetAd 的意外响应代码 307| .
有一段代码发出请求:
public class JsonObjectSend
{
private static final String TAG_action = "Action";
private static final String TAG_acValue = "ActionValue";
private static final String TAG_bg = "BgColor";
private static final String TAG_id = "CampId";
private static final String TAG_ctype = "CampType";
private static final String TAG_adr = "ClickAddress";
private static final String TAG_endAnim = "EndAnimation";
private static final String TAG_expText = "ExplainText";
private static final String TAG_imType = "ImageType";
private static final String TAG_imgUBanner = "ImageUrlBanner";
private static final String TAG_imgULBanner = "ImageUrlLargBanner";
private static final String TAG_imgUMRect = "ImageUrlMediumRectange";
private static final String TAG_imgUFBanner = "ImageUrlFullBanner";
private static final String TAG_imgULeadBrd = "ImageUrlLeaderBoard";
private static final String TAG_logoU = "LogoUrl";
private static final String TAG_mainText = "MainText";
private static final String TAG_packName = "PackageName";
private static final String TAG_repText = "ReplaceText";
private static final String TAG_startAnim = "StartAnimation";
private static final String TAG_videoU = "VideoUrl";
private static final String TAG_type = "type";
private static final String TAG_atag = "atag";
private static final String TAG_msg = "message";
private static final String TAG_pix = "pixel";
private static final String TAG_scrpt = "script";
private static final String TAG_tkn = "token";
public void sendobj()
{
JSONObject jsonBody = new JSONObject();
try {
jsonBody.put("DeviceId", "sdasda");
jsonBody.put("AppId", "ECC7BCE40126408386BCFCF8AB9187E7");
jsonBody.put("AdType", "text");
jsonBody.put("Location", "35.7209331,51.472983");
jsonBody.put("UserOperator", "Irancell");
jsonBody.put("Ip", "127.0.0.1");
jsonBody.put("NetworkType", "3G");
jsonBody.put("DeviceType", "Android");
jsonBody.put("DeviceBrand", "Samsung");
jsonBody.put("Width", "0");
jsonBody.put("Height", "0");
jsonBody.put("TestMode", "true");
} catch (JSONException e) {
e.printStackTrace();
}
String tag_string_req = "Send_Object";
JsonObjectRequest Req = new JsonObjectRequest(Request.Method.POST, AppConfig.API_URL, jsonBody, new Response.Listener<JSONObject>()
{
@Override
public void onResponse(JSONObject response)
{
try
{
JSONObject jObj = response;
boolean error = jObj.getBoolean("error");
if (!error)
{
String action = jObj.getString(TAG_action);
String actionvalue = jObj.getString(TAG_acValue);
String bg = jObj.getString(TAG_bg);
String campid = jObj.getString(TAG_id);
String camptype = jObj.getString(TAG_ctype);
String clickadr = jObj.getString(TAG_adr);
String endanim = jObj.getString(TAG_endAnim);
String exptext = jObj.getString(TAG_expText);
String imgtype = jObj.getString(TAG_imType);
String imgurlbanner = jObj.getString(TAG_imgUBanner);
String imgurllargebanner = jObj.getString(TAG_imgULBanner);
String imgurlmedrectangle = jObj.getString(TAG_imgUMRect);
String imgurlfullbanner = jObj.getString(TAG_imgUFBanner);
String imgurlleaderboard = jObj.getString(TAG_imgULeadBrd);
String logourl = jObj.getString(TAG_logoU);
String maintext = jObj.getString(TAG_mainText);
String packagename = jObj.getString(TAG_packName);
String replacetext = jObj.getString(TAG_repText);
String startenim = jObj.getString(TAG_startAnim);
String videourl = jObj.getString(TAG_videoU);
String type = jObj.getString(TAG_type);
String atag = jObj.getString(TAG_atag);
String msg = jObj.getString(TAG_msg);
String pixel = jObj.getString(TAG_pix);
String script = jObj.getString(TAG_scrpt);
String token = jObj.getString(TAG_tkn);
Log.d("action", action);
} else
{
String errorMsg = jObj.getString("error_msg");
Log.d("Debug", errorMsg);
}
}
catch (JSONException e)
{
e.printStackTrace();
}
}
}, new Response.ErrorListener()
{
@Override
public void onErrorResponse(VolleyError error)
{
Log.d("error","Error");
}
}) {
@Override
protected Map<String, String> getParams() throws AuthFailureError
{
// Posting params to register url
Map<String, String> params = new HashMap<String, String>();
params.put("Content-Type", "application/json; charset=utf-8");
return params;
}//
};
// Adding request to request queue
AppController.getInstance().addToRequestQueue(Req, tag_string_req);
}
}//class end
这是我的应用程序 Controller 类:
public class AppController extends Application
{
public static final String TAG = AppController.class.getSimpleName();
private RequestQueue mRequestQueue;
private static AppController mInstance;
@Override
public void onCreate()
{
super.onCreate();
mInstance = this;
}
public static synchronized AppController getInstance()
{
return mInstance;
}
public RequestQueue getRequestQueue()
{
if (mRequestQueue == null)
{
// mRequestQueue = Volley.newRequestQueue(getApplicationContext());
Network network = new BasicNetwork(new OkHttpStack());
mRequestQueue = new RequestQueue(new DiskBasedCache(new File(getCacheDir(), "volley")), network);
mRequestQueue.start();
}
return mRequestQueue;
}
public class OkHttpStack extends HurlStack
{
private final OkUrlFactory mFactory;
public OkHttpStack()
{
this(new OkHttpClient());
}
private OkHttpClient getUnsafeOkHttpClient()
{
try {
final TrustManager[] trustAllCerts = new TrustManager[]
{
new X509TrustManager()
{
@Override
public void checkClientTrusted(java.security.cert.X509Certificate[] chain, String authType) {}
@Override
public void checkServerTrusted(java.security.cert.X509Certificate[] chain, String authType) {}
@Override
public java.security.cert.X509Certificate[] getAcceptedIssuers()
{
return null;
}
}
};
final SSLContext sslContext = SSLContext.getInstance("SSL");
sslContext.init(null, trustAllCerts, new java.security.SecureRandom());
final SSLSocketFactory sslSocketFactory = sslContext.getSocketFactory();
OkHttpClient okHttpClient = new OkHttpClient();
okHttpClient.setSslSocketFactory(sslSocketFactory);
okHttpClient.setHostnameVerifier(new HostnameVerifier()
{
@Override
public boolean verify(String hostname, SSLSession session)
{
return true;
}
});
return okHttpClient;
}
catch (Exception e)
{
throw new RuntimeException(e);
}
}
public OkHttpStack(OkHttpClient client)
{
client=getUnsafeOkHttpClient();
if (client == null)
{
throw new NullPointerException("Client must not be null.");
}
mFactory = new OkUrlFactory(client);
}
@Override
protected HttpURLConnection createConnection(URL url) throws IOException
{
return mFactory.open(url);
}
}
public <T> void addToRequestQueue(Request<T> req, String tag)
{
req.setTag(TextUtils.isEmpty(tag) ? TAG : tag);
getRequestQueue().add(req);
}
public <T> void addToRequestQueue(Request<T> req)
{
req.setTag(TAG);
getRequestQueue().add(req);
}
public void cancelPendingRequests(Object tag)
{
if (mRequestQueue != null)
{
mRequestQueue.cancelAll(tag);
}
}
}
这是我的完整日志:
06-17 23:20:54.637 14338-14338/? I/art﹕ Late-enabling -Xcheck:jni
06-17 23:20:54.751 14338-14338/ir.adro.adrosdk I/WebViewFactory﹕ Loading com.android.webview version 37 (eng.buildbot-x86) (code 199997)
06-17 23:20:54.757 14338-14338/ir.adro.adrosdk I/LibraryLoader﹕ Loading: webviewchromium
06-17 23:20:54.758 14338-14338/ir.adro.adrosdk I/LibraryLoader﹕ Time to load native libraries: 1 ms (timestamps 9529-9530)
06-17 23:20:54.758 14338-14338/ir.adro.adrosdk I/LibraryLoader﹕ Expected native library version number "",actual native library version number ""
06-17 23:20:54.766 14338-14338/ir.adro.adrosdk V/WebViewChromiumFactoryProvider﹕ Binding Chromium to main looper Looper (main, tid 1) {39d8cd06}
06-17 23:20:54.767 14338-14338/ir.adro.adrosdk I/LibraryLoader﹕ Expected native library version number "",actual native library version number ""
06-17 23:20:54.767 14338-14338/ir.adro.adrosdk I/chromium﹕ [INFO:library_loader_hooks.cc(106)] Chromium logging enabled: level = 0, default verbosity = 0
06-17 23:20:54.771 14338-14338/ir.adro.adrosdk I/BrowserStartupController﹕ Initializing chromium process, renderers=0
06-17 23:20:54.771 14338-14338/ir.adro.adrosdk W/art﹕ Attempt to remove local handle scope entry from IRT, ignoring
06-17 23:20:54.775 14338-14338/ir.adro.adrosdk W/chromium﹕ [WARNING:resource_bundle.cc(315)] locale_file_path.empty()
06-17 23:20:54.776 14338-14338/ir.adro.adrosdk I/chromium﹕ [INFO:aw_browser_main_parts.cc(63)] Load from apk succesful, fd=32 off=46092 len=2953
06-17 23:20:54.776 14338-14338/ir.adro.adrosdk I/chromium﹕ [INFO:aw_browser_main_parts.cc(78)] Loading webviewchromium.pak from, fd:33 off:228796 len:643667
06-17 23:20:54.780 14338-14358/ir.adro.adrosdk W/AudioManagerAndroid﹕ Requires BLUETOOTH permission
06-17 23:20:54.787 14338-14338/ir.adro.adrosdk D/libEGL﹕ loaded /system/lib/egl/libEGL_emulation.so
06-17 23:20:54.788 14338-14338/ir.adro.adrosdk D/libEGL﹕ loaded /system/lib/egl/libGLESv1_CM_emulation.so
06-17 23:20:54.797 14338-14338/ir.adro.adrosdk D/libEGL﹕ loaded /system/lib/egl/libGLESv2_emulation.so
06-17 23:20:54.806 14338-14338/ir.adro.adrosdk D/﹕ HostConnection::get() New Host Connection established 0xa363fc10, tid 14338
06-17 23:20:54.859 14338-14338/ir.adro.adrosdk W/chromium﹕ [WARNING:mailbox_synchronizer.cc(36)] MailboxSync not supported due to missing EGL image/fence support
06-17 23:20:54.871 14338-14338/ir.adro.adrosdk W/chromium﹕ [WARNING:data_reduction_proxy_settings.cc(403)] SPDY proxy OFF at startup
06-17 23:20:54.881 14338-14338/ir.adro.adrosdk W/art﹕ Attempt to remove local handle scope entry from IRT, ignoring
06-17 23:20:54.882 14338-14338/ir.adro.adrosdk W/AwContents﹕ onDetachedFromWindow called when already detached. Ignoring
06-17 23:20:54.908 14338-14364/ir.adro.adrosdk W/chromium﹕ [WARNING:proxy_service.cc(901)] PAC support disabled because there is no system implementation
06-17 23:20:54.910 14338-14379/ir.adro.adrosdk D/OpenGLRenderer﹕ Render dirty regions requested: true
06-17 23:20:54.912 14338-14338/ir.adro.adrosdk D/Atlas﹕ Validating map...
06-17 23:20:54.980 14338-14379/ir.adro.adrosdk I/OpenGLRenderer﹕ Initialized EGL, version 1.4
06-17 23:20:54.980 14338-14379/ir.adro.adrosdk D/﹕ HostConnection::get() New Host Connection established 0xa1f9fdc0, tid 14379
06-17 23:20:55.005 14338-14379/ir.adro.adrosdk D/OpenGLRenderer﹕ Enabling debug mode 0
06-17 23:20:55.023 14338-14379/ir.adro.adrosdk W/EGL_emulation﹕ eglSurfaceAttrib not implemented
06-17 23:20:55.023 14338-14379/ir.adro.adrosdk W/OpenGLRenderer﹕ Failed to set EGL_SWAP_BEHAVIOR on surface 0xa1fba7a0, error=EGL_SUCCESS
06-17 23:20:55.235 14338-14377/ir.adro.adrosdk E/Volley﹕ [199] BasicNetwork.performRequest: Unexpected response code 307 for http://phoneapi.adro.co/Services/AdService.svc/GetAd
06-17 23:20:55.235 14338-14338/ir.adro.adrosdk D/error﹕ Error
谁能告诉我为什么我总是收到这个错误?
最佳答案
您可以通过添加 /
来避免 307 响应代码在您的网址末尾,即 http://phoneapi.adro.co/Services/AdService.svc/GetAd/
然后使用以下示例代码(我使用了你的 jsonBody
),你应该更多地检查你的网络服务,因为这段代码将得到 400 响应代码
JsonObjectRequest request = new JsonObjectRequest(Request.Method.POST, url, jsonBody, new Response.Listener<JSONObject>() {
@Override
public void onResponse(JSONObject response) {
Log.i("onResponse", response.toString());
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
Log.i("onErrorResponse", error.toString());
}
}){
@Override
protected VolleyError parseNetworkError(VolleyError volleyError) {
if(volleyError.networkResponse != null && volleyError.networkResponse.data != null){
VolleyError error = new VolleyError(new String(volleyError.networkResponse.data));
volleyError = error;
}
return volleyError;
}
};
调试时(在VolleyError error = new VolleyError(new String(volleyError.networkResponse.data));
设置断点),会得到一些信息如
The server encountered an error processing the request. The exception message is 'Object reference not set to an instance of an object.'. See server logs for more details. The exception stack trace is: </p>
<p> at AdroMobileApi.Services.AdService.GetAd(AdRequest request)
at SyncInvokeGetAd(Object , Object[] , Object[] )
at System.ServiceModel.Dispatcher.SyncMethodInvoker.Invoke(Object instance, Object[] inputs, Object[]& outputs)
at System.ServiceModel.Dispatcher.DispatchOperationRuntime.InvokeBegin(MessageRpc& rpc)
at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage5(MessageRpc& rpc)
at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage11(MessageRpc& rpc)
at System.ServiceModel.Dispatcher.MessageRpc.Process(Boolean isOperationContextSet)</p>
关于android - E/Volley:[194] BasicNetwork.performRequest : Unexpected response code 307 for url,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37892945/
code
正常吗?
我刚刚开始使用 YARD 来记录我的 Rails 应用程序。我没有指定任何特定的标记处理程序,但我希望 `code` 会转换为 code,但这似乎没有发生。这是正常行为吗?我是否必须添加一些额外的选项
什么是Code-Server 首先程序员朋友们肯定都用过来自微软的VS Code 这款轻量而又高级的编辑器,拥有丰富的插件库,支持各种语言编译运行。而本文介绍的Code-Server就是coder 公
我是一名高中生,今年开始学习汇编。 我目前正在制作 Pacman 克隆作为我的最终项目。 我遇到的唯一问题是我的代码很大,*.exe 文件几乎有 64KB。 所以我的问题是,如果我转向模型介质,我需要
锁定。这个问题及其答案是locked因为这个问题是题外话,但具有历史意义。它目前不接受新的答案或互动。 挑战 按字符计数绘制 Code 39 条码的 ASCII 表示的最短代码。 维基百科关于代码 3
我正在开发 VS 代码的扩展(使用 javascript)。现在我需要安装 VS Code 的路径。 windows有一种方法: var child = require('child_process'
[Windows 10] 我在自定义目录中安装了“Microsoft VS Code(用户设置)”,每当我尝试更新它时,都会显示: 然后这个 Log Info Dec 23 11:42:40.673
我正在尝试更新我的 VS 代码,但收到一条错误消息:由于防病毒软件和/或进程失控,更新可能会失败。 附加了一个来 self 的用户的日志文件,但我不确定要检查什么。我对计算机和编程还是个新手。 最佳答
几天前我安装了 Kali Linux。我正在尝试使用 Code-OSS 而不是 VSCode,因为最新版本的 Kali 没有安装普通版本所需的库。 如果我尝试使用 code-oss . 或 code
我正在从 Atom 迁移到 VS Code,因为这似乎是当今所有酷 child 都在使用的东西。 在 atom 中,我能够如图所示突出显示当前行号(装订线中的蓝色突出显示)。 有没有办法在 VS Co
我试图找到一个明确的 G 代码语法规范,而不是单个 G 代码的含义,我无处不在的规范,我的意思是详细的语法规范,目的是编写解析器。 我编写解析器没有问题,我只是在寻找语法规范,例如。我知道您不必总是为
我想在 VS Code (Windows) 中使用 Fira Code,并且已经按照 instructions 中的说明配置了字体。 。不知何故,字体看起来很模糊。我该如何解决这个问题? "edito
这个问题已经有答案了: How can I navigate back to the last cursor position in Visual Studio Code? (16 个回答) 已关闭
如何选择当前单词,即插入符号所在的位置。 注意:我正在寻找 Visual Studio Code(VS Code)(文本编辑器)的快捷方式,而不是 Visual Studio IDE。 最佳答案 在
我需要在 VS Code 中安装 flutter 但在安装扩展中,我有这个错误 Unable to install 'Dart-Code.flutter'; there is no available
memberData
有什么区别
{@code memberData} 和有什么区别?和 memberData在 JavaDoc 中 最佳答案 有两个主要区别: {@code ...}更简洁:更易于阅读(和输入)。 {@code ..
我有这样一个字符串: Here is my code sample, its not too great: [CODE] [/CODE] I hope you enjoy. 现在我想用 highli
在 VS Code 中,我有一个少于 50 个文件的 Vue 项目,但是在运行开发服务器时 VS Code 抛出 Error: ENOSPC: System limit for number of f
Source Code Pro 如何在 VSC 中使用 ExtraLight ~? 似乎以下不起作用...... 我确定我有字体。 Source Code Pro ExtraLight 最佳答案 编辑
我对 Visual Studio Code 很陌生。我正在尝试调试一个已经存在的应用程序,我已经通过 Git 克隆了它。我的文件都没有被修改。我已经下载了微软扩展“C# for Visual Stud
Visual Code VS Visual Studio Code Insider 我还是不明白这两者有什么区别,难道其中一个是新功能的试用版吗? 最佳答案 Visual Studio Code In
我是一名优秀的程序员,十分优秀!