Open troy21688 opened 8 years ago
I think the correct forums for this would be someone more familiar with retrofit and how it might handle toast creation or other problems... However to help you debug you can look at your server side logs. Perhaps that will give you some insight into whether you are even sending a request. Check the google developer console logging to see what requests are coming in.
I made a previous post and appear to have made progress, but please see the StackOverflow post for reference: http://stackoverflow.com/questions/35068601/how-to-handle-jsonsyntaxexception-when-receiving-response-from-gae
I am trying to replicate the Google App Engine Servlets module [here][1] using Retrofit instead of AsyncTask.
I find it odd, but apparently Retrofit 2.0 does not support connections to Google App Engine, as stated [here][2] in the issues of the GitHub repository.
As a result, I am using Retrofit 1.9 and OkHttp 2.3 dependencies.
I have created a project called "Retrofit Test" in the Google Developer Console, and Google has supplied me with a URL for the project: "http://retrofit-test-1203.appspot.com" with the subdomain as "http://retrofit-test-1203.appspot.com/hello. These will be my respective URL's for Retrofit. Below is my code:
Gradle:
MainActivity:
public class MainActivity extends AppCompatActivity {
//set the URL of the server, as defined in the Google Servlets Module Documentation private static String PROJECT_URL = "http://retrofit-test-1203.appspot.com"; private Button mTestButton;
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); setSupportActionBar(toolbar); mTestButton = (Button) findViewById(R.id.test_button);
} }
My Servlet:
public class MyServlet extends HttpServlet { @Override public void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException { resp.setContentType("text/plain"); resp.getWriter().println("Please use the form to POST to this url"); }
@Override public void doPost(HttpServletRequest req, HttpServletResponse resp) throws IOException { String name = req.getParameter("name"); resp.setContentType("text/plain"); if(name == null) { resp.getWriter().println("Please enter a name"); } resp.getWriter().println("Hello " + name); } }