我正在使用okhttp3
将我的Android应用程序连接到我的mysql
数据库,但是在使用FormBody.Builder()
时我发现错误(我看到其他人使用此方法)。
我需要执行一个帖子请求。
OkHttpClient client = new OkHttpClient();
RequestBody formBody = new FormBody.Builder() //this FormBody gives "Cannot resolve symbol FormBody"
.add("name", reg_name)
.add("pass", reg_pass)
.build();
Request request = new Request.Builder()
.url(reg_url)
.post(formBody)
.build();
答案 0 :(得分:1)
看起来你使用的是错误的okhttp版本。确保您的Gradle依赖关系指定如下:
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<div class="container" ng-app="myApp">
<div class="form-group">
<div class="row">
<div class="col-sm-8">
<div ng-switch="myVar">
<div ng-switch-when="dogs">
<div class="pricing-levels-3">
<p><strong>Which level would you like? (Select 3 Levels)</strong></p>
<input class="single-checkbox" type="checkbox" name="vehicle" value="Bike">Level 1<br>
<input class="single-checkbox" type="checkbox" name="vehicle" value="Bike">Level 2<br>
<input class="single-checkbox" type="checkbox" name="vehicle" value="Bike">Level 3<br>
<input class="single-checkbox" type="checkbox" name="vehicle" value="Bike">Level 4<br>
<input class="single-checkbox" type="checkbox" name="vehicle" value="Bike">Level 5<br>
<input class="single-checkbox" type="checkbox" name="vehicle" value="Bike">Level 6<br>
<input class="single-checkbox" type="checkbox" name="vehicle" value="Bike">Level 7<br>
</div>
</div>
<div ng-switch-when="tuts">
<div class="pricing-levels-2">
<p><strong>Which level would you like? (Select 3 Levels)</strong></p>
<input class="single-checkbox1" type="checkbox" name="vehicle" value="Bike">Level 1<br>
<input class="single-checkbox1" type="checkbox" name="vehicle" value="Bike">Level 2<br>
<input class="single-checkbox1" type="checkbox" name="vehicle" value="Bike">Level 3<br>
</div>
</div>
<div ng-switch-when="cars">
<h1>Cars</h1>
<p>Read about cars.</p>
</div>
</div>
</div>
<div class="col-sm-4">
<h1>Select a topic:</h1>
<select ng-model="myVar" class="form-control">
<option value="dogs">Dogs</option>
<option value="tuts">Tutorials</option>
<option value="cars">Cars</option>
</select>
</div>
</div>
</div>
</div>
(或最合适的版本号)
另外,请务必包含相应的import语句:
compile 'com.squareup.okhttp3:okhttp:3.9.0'