实际上我想通过retrofit2 api从Mysql数据库中获取数据。我是根据类别1或类别等某些类别获取数据但我收到错误<?php
require 'functions.php';
$body = "";
$score = 0;
$count = 0;
$newFdigit = randdigit();
$newSdigit = randdigit();
$newOperator = randop();
if(isset($_POST['submit']))
{
$firstDigit = $_POST['lho'];
$secondDigit = $_POST['rho'];
$operator = $_POST['op'];
$userAnswer = $_POST['answer'];
$count = $_POST['count'];
$score = $_POST['score'];
$answer = evaluate($firstDigit, $secondDigit, $operator);
if($answer == $userAnswer)
{
$count++;
$score++;
$body .= "\n<h1>Congratulations!</h1>\n\n";
$body .= "$score out of $count";
}
else
{
$count++;
$body .= "\n<h1>Sorry!</h1>\n\n";
$body .= "$score out of $count";
}
}
header( 'Content-Type: text/html; charset=utf-8');
print("<?xml version=\"1.0\" encoding=\"utf-8\"?>\n");
?>
<h1>Math Quiz</h1> <br /> <br />
<?php
print $body;
?>
<form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
<h3><?php echo $newFdigit; ?> <?php echo $newOperator; ?> <?php echo $newSdigit; ?> = ?
<input type="text" name="answer" size="2" /></h3>
<p><input type="submit" name="submit" value="Try It!" />
<input type="hidden" name="lho" value="<?php echo $newFdigit ?>" />
<input type="hidden" name="rho" value="<?php echo $newSdigit; ?>" />
<input type="hidden" name="op" value="<?php echo $newOperator; ?>" />
<input type="hidden" name="score" value="<?php echo $score++; ?>" />
<input type="hidden" name="count" value="<?php echo $count++; ?>" /></p>
</form>
这是我的界面代码:
@Field parameters can only be used with form encoding. (parameter #1)for method APIService.savePost
这是我的ApiUtils课程:
public interface APIService {
@GET("fetchtext.php")
Call<List<DataStored>> savePost(@Field("catId") String catId);
@GET("testing.php")
Call<List<DataStored>> searchcategory(@Field("catId") String catId,
@Field("SubCatego") String SubCatego);
}
RetrofitClient类:
public class ApiUtils {
private ApiUtils() {}
public static final String BASE_URL = "http://192.168.9.10/";
public static APIService getAPIService() {
return RetrofitClient.getClient(BASE_URL).create(APIService.class);
}
}
我在创建调用RetroApi的片段中的代码:
public class RetrofitClient {
private static Retrofit retrofit = null;
public static Retrofit getClient(String baseUrl) {
if (retrofit==null) {
retrofit = new Retrofit.Builder()
.baseUrl(baseUrl)
.addConverterFactory(GsonConverterFactory.create())
.build();
}
return retrofit;
}}
请告诉我如何将类别发送到数据库以进行比较 数据库中可用的类别数据然后数据转换为Json并在android中发送回以在android中的RecyclerView上显示。
答案 0 :(得分:0)
@GET("fetchtext.php")
Call<List<DataStored>> savePost(@Field("catId") String catId);
@Field用于发送POST数据。要获取数据,您应该使用@Query
@GET("fetchtext.php")
Call<List<DataStored>> savePost(@Query("catId") String catId);