且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

HTTP /在改造后的android法1.1 500内部服务器错误?

更新时间:2022-10-20 16:41:15

试试这个code:

 的JSONObject为userDetails =新的JSONObject();
        尝试{
            userDetails.put(EMAILID,emailid.getText()的toString());
            userDetails.put(密码,password.getText()的toString());
            userDetails.put(的DeviceID,DEVICEID);
            userDetails.put(PlatformID,WebUrl.platformid);
            userDetails.put(DeviceTokenREGID);
            userDetails.put(Mobilemodel,Mobilemodel);
            userDetails.put(Appversion,1.2.8.2);
            userDetails.put(MobileOS,MobileOs);
            Log.v(TAG_USERDEATILS,+为userDetails);
        }赶上(JSONException E){
            // TODO自动生成catch块
            e.printStackTrace();
        }
TypedInput体=新TypedByteArray(应用/ JSON,userDetails.toString()的getBytes(UTF-8));
serviceClient.getUserInfo(身体,
                回电话);

希望这有助于!

I started learning and working retrofit recently. "Get" method is working fine. but when i am using "Post" method it gives me HTML page as response.

my code is:

ServiceClient:

public interface ServiceClient {

    String SERVICE_ENDPOINT = "https://ghrth.in/rjk/AppServices.asmx";

    @POST("/user_v2")
    void getUserInfo(@Body TypedInput in, Callback<JsonObject> callback);
}

ServiceUtil:

public class ServiceUtil {

    public static ServiceClient getServiceClient() {

        RestAdapter restAdapter = new RestAdapter.Builder().setEndpoint(
                ServiceClient.SERVICE_ENDPOINT)
                .setLogLevel(LogLevel.FULL)
                .build();

        ServiceClient serviceClient = restAdapter.create(ServiceClient.class);
        return serviceClient;
    }

    public static class TypedJsonString extends TypedString {
        public TypedJsonString(String body) {
            super(body);
        }

        @Override
        public String mimeType() {
            return "application/json";
        }
    }
}

Activity:

 login_btn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (emailid.getText().toString().length() == 0 || password.getText().toString().length() == 0
                        ) {
                    Toast.makeText(getApplicationContext(), "Enter All Fields",
                            Toast.LENGTH_LONG).show();
                } else if (!validEmail(emailid.getText().toString())) { //if (!emailStr.matches("[a-zA-Z0-9._-]+@[a-z]+\\.+[a-z]+")) {
                    Toast.makeText(getApplicationContext(),
                            "Enter valid email id", Toast.LENGTH_LONG).show();
                } else {

                    boolean flag = checkNet(getApplicationContext());
                    if (flag) {
                        enableGCM();
                        onSucceeded();
                    } else {
                        showAlert(Login_Activity.this, "No Internet Access");
                    }
                }


            }
        });
   public void onSucceeded() {



        ServiceClient serviceClient = ServiceUtil.getServiceClient();
        JSONObject userDetails = new JSONObject();
        try {
            userDetails.put("Emailid", emailid.getText().toString());
            userDetails.put("Password", password.getText().toString());
            userDetails.put("DeviceID", DEVICEID);
            userDetails.put("PlatformID", WebUrl.platformid);
            userDetails.put("DeviceToken", regid);
            userDetails.put("Mobilemodel", Mobilemodel);
            userDetails.put("Appversion", "1.2.8.2");
            userDetails.put("MobileOS", MobileOs);
Log.v("TAG_USERDEATILS",""+userDetails);
        } catch (JSONException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }



        serviceClient.getUserInfo(new ServiceUtil.TypedJsonString(userDetails.toString()),
                callback);
    }
    Callback<JsonObject> callback = new Callback<JsonObject>() {

        @Override
        public void success(JsonObject resultUserInfo, Response response) {
            Log.v("TAG_SUCCESS",""+resultUserInfo);

        }

        @Override
        public void failure(RetrofitError error) {

        }
    };

logcat:

08-20 11:29:35.751  31958-32374/com.rrtyu.reg D/Retrofit﹕ <--- HTTP 500 https://ghrth.in/rjk/AppServices.asmx/user_v2 (963ms)
08-20 11:29:35.751  31958-32374/com.rrtyu.reg D/Retrofit﹕ : HTTP/1.1 500 Internal Server Error
08-20 11:29:35.751  31958-32374/com.reloadapp.reload D/Retrofit﹕ Access-Control-Allow-Origin: *
08-20 11:29:35.751  31958-32374/com.reloadapp.reload D/Retrofit﹕ Cache-Control: private
08-20 11:29:35.751  31958-32374/com.rrtyu.reg D/Retrofit﹕ Content-Length: 5041
08-20 11:29:35.751  31958-32374/com.rrtyu.reg D/Retrofit﹕ Content-Type: text/html; charset=utf-8
08-20 11:29:35.751  31958-32374/com.rrtyu.reg D/Retrofit﹕ Date: Thu, 20 Aug 2015 05:53:51 GMT
08-20 11:29:35.751  31958-32374/com.rrtyu.reg D/Retrofit﹕ ETag: ""
08-20 11:29:35.751  31958-32374/com.rrtyu.regD/Retrofit﹕ Server: Microsoft-IIS/8.0
08-20 11:29:35.751  31958-32374com.rrtyu.reg D/Retrofit﹕ X-Android-Received-Millis: 1440050375757
08-20 11:29:35.751  31958-32374/com.reloadapp.reload D/Retrofit﹕ X-Android-Sent-Millis: 1440050374825
08-20 11:29:35.751  31958-32374/com.rrtyu.reg D/Retrofit﹕ X-AspNet-Version: 4.0.30319
08-20 11:29:35.761  31958-32374/com.rrtyu.reg D/Retrofit﹕ <!DOCTYPE html>
    <html>
    <head>
    <title>Only Web services with a [ScriptService] attribute on the class definition can be called from script.</title>
    <meta name="viewport" content="width=device-width" />
    <style>
    body {font-family:"Verdana";font-weight:normal;font-size: .7em;color:black;}
    p {font-family:"Verdana";font-weight:normal;color:black;margin-top: -5px}
    b {font-family:"Verdana";font-weight:bold;color:black;margin-top: -5px}
    H1 { font-family:"Verdana";font-weight:normal;font-size:18pt;color:red }
    H2 { font-family:"Verdana";font-weight:normal;font-size:14pt;color:maroon }
    pre {font-family:"Consolas","Lucida Console",Monospace;font-size:11pt;margin:0;padding:0.5em;line-height:14pt}
    .marker {font-weight: bold; color: black;text-decoration: none;}
    .version {color: gray;}
    .error {margin-bottom: 10px;}
    .expandable { text-decoration:underline; font-weight:bold; color:navy; cursor:hand; }
    @media screen and (max-width: 639px) {
    pre { width: 440px; overflow: auto; white-space: pre-wrap; word-wrap: break-word; }
    }
    @media screen and (max-width: 479px) {
    pre { width: 280px; }
    }
    </style>
    </head>
    <body bgcolor="white">
    <span><H1>Server Error in '/' Application.<hr width=100% size=1 color=silver></H1>
    <h2> <i>Only Web services with a [ScriptService] attribute on the class definition can be called from script.</i> </h2></span>
    <font face="Arial, Helvetica, Geneva, SunSans-Regular, sans-serif ">
    <b> Description: </b>An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
    <br><br>
    <b> Exception Details: </b>System.InvalidOperationException: Only Web services with a [ScriptService] attribute on the class definition can be called from script.<br><br>
    <b>Source Error:</b> <br><br>
    <table width=100% bgcolor="#ffffcc">
    <tr>
    <td>
    <code>
    An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.</code>
    </td>
    </tr>
    </table>
    <br>
    <b>Stack Trace:</b> <br><br>
    <table width=100% bgcolor="#ffffcc">
    <tr>
    <td>
    <code><pre>
    [InvalidOperationException: Only Web services with a [ScriptService] attribute on the class definition can be called from script.]
    System.Web.Script.Services.WebServiceData..ctor(Type type, Boolean pageMethods) +774816
    System.Web.Script.Services.WebServiceData.GetWebServiceData(HttpContext context, String virtualPath, Boolean failIfNoData, Boolean pageMethods, Boolean inlineScript) +304
    System.Web.Script.Services.RestHandler.CreateHandler(HttpContext context) +136
    System.Web.Script.Services.ScriptHandlerFactory.GetHandler(HttpContext context, String requestType, String url, String pathTranslated) +89
    System.Web.MaterializeHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +516
    System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean&amp; completedSynchronously) +288
    </pre></code>
    </td>
    </tr>
    </table>
    <br>
    <hr width=100% size=1 color=silver>
    <b>Version Information:</b>&nbsp;Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.17929
    </font>
    </body>
    </html>
    <!--
    [InvalidOperationException]: Only Web services with a [ScriptService] attri
08-20 11:29:35.761  31958-32374/com.rrtyu.reg D/Retrofit﹕ bute on the class definition can be called from script.
            at System.Web.Script.Services.WebServiceData..ctor(Type type, Boolean pageMethods)
            at System.Web.Script.Services.WebServiceData.GetWebServiceData(HttpContext context, String virtualPath, Boolean failIfNoData, Boolean pageMethods, Boolean inlineScript)
            at System.Web.Script.Services.RestHandler.CreateHandler(HttpContext context)
            at System.Web.Script.Services.ScriptHandlerFactory.GetHandler(HttpContext context, String requestType, String url, String pathTranslated)
            at System.Web.HttpApplication.MaterializeHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
            at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)
    --><!--
    This error page might contain sensitive information because ASP.NET is configured to show verbose error messages using &lt;customErrors mode="Off"/&gt;. Consider using &lt;customErrors mode="On"/&gt; or &lt;customErrors mode="RemoteOnly"/&gt; in production environments.-->
08-20 11:29:35.761  31958-32374/com.reloadapp.reload D/Retrofit﹕ <--- END HTTP (5041-byte body)

Try this code:

JSONObject userDetails = new JSONObject();
        try {
            userDetails.put("Emailid", emailid.getText().toString());
            userDetails.put("Password", password.getText().toString());
            userDetails.put("DeviceID", DEVICEID);
            userDetails.put("PlatformID", WebUrl.platformid);
            userDetails.put("DeviceToken", regid);
            userDetails.put("Mobilemodel", Mobilemodel);
            userDetails.put("Appversion", "1.2.8.2");
            userDetails.put("MobileOS", MobileOs);
            Log.v("TAG_USERDEATILS",""+userDetails);
        } catch (JSONException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
TypedInput body = new TypedByteArray("application/json", userDetails.toString().getBytes("UTF-8"));
serviceClient.getUserInfo(body,
                callback);

Hope this helps!