Php 尝试使用REST web服务时获取403(禁止)
我试图在我的android应用程序中使用REST web服务,状态代码中总是有403。 web服务由安装在Wampserver上的web应用程序提供。我尝试使用的方法是glpi.doLogin,它接受两个prams用户名和密码。它在我的浏览器上运行良好。代码如下: 包com.example.wsPhp 尝试使用REST web服务时获取403(禁止),php,android,rest,Php,Android,Rest,我试图在我的android应用程序中使用REST web服务,状态代码中总是有403。 web服务由安装在Wampserver上的web应用程序提供。我尝试使用的方法是glpi.doLogin,它接受两个prams用户名和密码。它在我的浏览器上运行良好。代码如下: 包com.example.ws import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; import java.io
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import org.apache.http.HttpEntity;
import org.apache.http.HttpHost;
import org.apache.http.HttpRequest;
import org.apache.http.HttpResponse;
import org.apache.http.StatusLine;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpClient;
import org.apache.http.client.ResponseHandler;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.client.methods.HttpUriRequest;
import org.apache.http.conn.ClientConnectionManager;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.params.HttpParams;
import org.apache.http.protocol.HttpContext;
import org.json.JSONObject;
import android.os.AsyncTask;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;
import android.app.Activity;
public class MainActivity extends Activity {
HttpClient client;
HttpGet httpGet;
HttpResponse reponce;
public Toast toast;
public static final String TAG ="Mon_TAG";
public TextView letexte;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
letexte= (TextView) findViewById(R.id.letexte);
Button btn = (Button) findViewById(R.id.MyBtn);
btn.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
c();
}
});
}
public void c(){
client = new DefaultHttpClient();
httpGet = new HttpGet("http://169.254.101.101:80/plugins/webservices/rest.php?method=glpi.doLogin&login_name=glpi&login_password=glpi");
Thread t = new Thread(new t());
t.start();
if(reponce != null){
try{
StatusLine status = reponce.getStatusLine();
int codeStatus = status.getStatusCode();
if(codeStatus != 200){
String su = "status code = "+ codeStatus;
update(su);
}
else{
HttpEntity corps = reponce.getEntity();
InputStream is = corps.getContent();
BufferedReader br = new BufferedReader(new InputStreamReader(is));
StringBuilder s = new StringBuilder();
String r;
while((r = br.readLine()) != null){
s.append(r);
}
String stringFinal = s.toString();
update(stringFinal);
}
}
catch(IOException e){
String s = "Error cnx";
update(s);
}
}
else update("reponce null");
}
public void update(String s){
letexte.setText(s);
}
class t implements Runnable {
public void run(){
try{
reponce = client.execute(httpGet);
}
catch(IOException e){
Log.d("Thread","Error");
e.printStackTrace();
}
}
}
}
问题已解决。。。这是由于httpd.conf配置文件下的权限造成的!从您的IP地址添加“允许”。非常感谢。将您的评论转化为更详细的答案,并接受您的答案,这样问题就标记为有解决方案,其他人以后可以更好地参考它。