我使用安卓网络连接到服务器并发送图片到服务器,但我想发送时出现了错误:com.androidnetworking.error.ANError: com.androidnetworking.error.ANError。 我使用安卓网络连接到服务器并发送图片到服务器,但我想发送时出现了错误:com.androidnetworking.error.ANError:com.androidnetworking.error.ANError。
D/خطاااااااا: com.androidnetworking.error.ANError: com.androidnetworking.error.ANError: okhttp3.internal.http2.StreamResetException: stream was reset: PROTOCOL_ERROR
D/TextView: setTypeface with style : 0
D/ViewRootImpl@c2f4955[Main]: ViewPostImeInputStage processPointer 0
D/ViewRootImpl@c2f4955[Main]: ViewPostImeInputStage processPointer 1
D/خطاااااااا: com.androidnetworking.error.ANError: com.androidnetworking.error.ANError: okhttp3.internal.http2.ConnectionShutdownException
这就是程序的主体。
package com.example.myfaild;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.support.design.widget.Snackbar;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import com.androidnetworking.AndroidNetworking;
import com.androidnetworking.error.ANError;
import com.androidnetworking.interfaces.ParsedRequestListener;
public class LoginActivity extends AppCompatActivity {
EditText user , pass;
Button lgn;
TextView viewRegister;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_login);
user = this.<EditText>findViewById(R.id.editTextUsername);
pass = this.<EditText>findViewById(R.id.editTextPassword);
lgn = this.<Button>findViewById(R.id.buttonLogin);
viewRegister = this.<TextView>findViewById(R.id.textViewRegister);
final SessionManager manager = new SessionManager(this);
if (manager.isLoggedIn()){
startActivity(new Intent(LoginActivity.this, Main.class));
finish();
AndroidNetworking.initialize(this);
viewRegister.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
startActivity(new Intent(LoginActivity.this, SignUp.class));
finish();
lgn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (user.length()==0 || pass.length()==0){
Snackbar.make(v, "فیلد ها باید پرشود ! ", Snackbar.LENGTH_LONG).show();
return;
login(user.getText().toString(),pass.getText().toString(),manager, v);
private void login (final String username, String password, final SessionManager manager , final View v){
AndroidNetworking.post(URLS.host+URLS.login)
.addBodyParameter("username",username)
.addBodyParameter("password",password)
.setTag("LOGIN")
.build()
.getAsObject(User.class, new ParsedRequestListener<User>() {
@Override
public void onResponse(User response) {
if (response.getUsername().toLowerCase().equals(username.toLowerCase())){
manager.setLoggedIn(true);
SharedPreferences preferences = getSharedPreferences("pref", MODE_PRIVATE);
preferences.edit().putString("username",response.getUsername()).apply();
preferences.edit().putString("email", response.getUsername()).apply();
preferences.edit().putString("image", response.getImageUrl()).apply();
startActivity(new Intent(LoginActivity.this, Main.class));
finish();
}else{
Snackbar.make(v, "نام کاربری و رمز عبور مطابقت ندارد ! ", Snackbar.LENGTH_LONG).show();
@Override
public void onError(ANError anError) {
Log.d("خطاااااااا" ,String.valueOf(anError));
Snackbar.make(v, "خطا در ارتباط ! ", Snackbar.LENGTH_LONG).show();