我有一个Android应用程序在其他Android设备上运行良好,但它在运行Android 4.0.4数据的samsung s3上失败。改造抛出404(页面未找到错误),但页面存在,如果我在wifi上发出相同的请求,它运行良好。任何人都知道什么可能是行为不端。感谢
请在下面找到堆栈跟踪
retrofit.RetrofitError: 404 Not Found
at retrofit.RestAdapter$RestHandler.invokeRequest (RestAdapter.java:388)
at retrofit.RestAdapter$RestHandler.access$100 (RestAdapter.java:220)
at retrofit.RestAdapter$RestHandler$2.obtainResponse (RestAdapter.java:278)
at retrofit.CallbackRunnable.run (CallbackRunnable.java:42)
at java.util.concurrent.ThreadPoolExecutor.runWorker (ThreadPoolExecutor.java:1076)
at java.util.concurrent.ThreadPoolExecutor$Worker.run (ThreadPoolExecutor.java:569)
at retrofit.Platform$Android$2$1.run (Platform.java:142)
at java.lang.Thread.run (Thread.java:856)
以下是我用来拨打电话的代码
val tailorsInterface = RestAdapter.Builder()
.setEndpoint(resources.getString(R.string.base_url))
.build().create(TailorsInterface::class.java)
tailorsInterface.addTailor(txtName.text.toString(), txtEmail.text.toString(),
Utils.parsePhone(txtPhone.text.toString(), "254"), txtAddress.text.toString(),
txtLon.text.toString(), txtLat.text.toString(), txtPassword.text.toString(),
Common.LOCATIONS!!.get(spTowns.selectedItemPosition).id, object : Callback<DefaultResponse> {
override fun success(defaultResponse: DefaultResponse, response: Response) {
dialog.hide()
if(defaultResponse.success == 1.toLong()){
val alertDialog: AlertDialog
val builder = AlertDialog.Builder(this@TailorsRegisterActivity)
.setTitle(resources.getString(R.string.app_name))
.setMessage("Tailor successfully registered, click OK to continue to login")
.setPositiveButton("OK") { dialog, which -> run{dialog.dismiss()
val loginIntent: Intent = Intent(this@TailorsRegisterActivity, TailorsLoginActivity::class.java)
startActivity(loginIntent)
} }
alertDialog = builder.create()
alertDialog.show()
}else{
val alertDialog: AlertDialog
val builder = AlertDialog.Builder(this@TailorsRegisterActivity)
.setTitle(resources.getString(R.string.app_name))
.setMessage("An Error occurred please try again later")
.setPositiveButton("OK") { dialog, which -> run{dialog.dismiss()
finish()} }
alertDialog = builder.create()
alertDialog.show()
}
}
@FormUrlEncoded
@POST("/tailors")
public fun addTailor(@Field("name") name: String, @Field("email") email: String,
@Field("phone") phone: String, @Field("address") address: String,
@Field("lon") lon: String, @Field("lat") lat: String,
@Field("password") password: String, @Field("town") town: Int,
cb: Callback<DefaultResponse>)
data class DefaultResponse (
var success: Long,
var message: String
)
答案 0 :(得分:0)
经过多天的调试,试图找出问题后我终于找到了解决方案,问题不是改造,而是我正在使用的网络服务器。我在clojure中完成了我的应用程序,并且使用http-kit作为我的网络服务器和路由的组件。
由于某些原因,来自s3的请求http-kit请求映射中的uri也包含主机,因此它没有被映射到我的defroute上的任何路由。例如,如果我要查找的路线是/login
,来自s3的请求的http-kit请求图中的uri包含http://example.com/login
,但是来自其他手机的/login
。因此,uri不匹配我在compojure defroute中定义的任何路线,直接找不到,因此404错误
解决方案
要解决此问题,我必须延长Compojure routes.clj
并添加以下功能
(defn other-found
"if for some reason the route is defined and is not found "
[body]
(fn [request]
(-> (response/render body request)
(status 200)
(cond-> (= (:request-method request) :head) (assoc :body nil)))))
在defroute中,如果uri不匹配,我使用函数other-found
并将函数not-found-page
(您可以将此函数命名为任何您想要调用的函数)传递给函数我得到的函数来自request参数的uri解析它并获取端点然后使用condp
将端点映射到适当的函数。
希望这有助于遇到类似问题的人。