現在我正在開發一個Android應用程序,我對此完全陌生。將Web服務訪問限制爲只有一個應用程序
我想確保我的網絡服務只能通過我的應用程序訪問。
我的背景是PHP。在PHP中,我不需要擔心這樣的事情,因爲所有東西都在服務器上運行。
在Java和尤其是Android編程的情況下,情況有所不同。即使使用加密。每個人都可以打開一個APK,看看如何訪問Web服務。那麼有沒有辦法隱藏或混淆對Web服務的訪問,所以只有我的應用程序才能使用它?
出於測試目的,我沒有添加任何安全或加密。這是我現在正在做的Web服務器的基本呼叫:
String url = "http://thisismyurl.com/a.php?action=get";
String result = Web.executeWeb(url);
public class Web {
public static String executeWeb(final String url) {
final StringBuilder sb = new StringBuilder();
Thread thread = new Thread(new Runnable() {
public void run()
{
try
{
InputStream is = (InputStream) new URL(url).getContent();
BufferedReader reader = new BufferedReader(new InputStreamReader(is));
String result, line = reader.readLine();
result = line;
while((line=reader.readLine())!=null){
result+=line;
}
sb.append(result);
//System.out.println(result);
//Log.i("My Response :: ", result);
} catch (Exception e)
{
// TODO: handle exception
}
}
});
thread.start();
try {
thread.join();
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return sb.toString();
}
}
我該如何將這個從黑客的窺探中隱藏起來? ;-)這甚至可能嗎?
在此先感謝!