我正在使用json請求登錄並顯示與用戶有關的消息。但是如果我從瀏覽器發出相同的請求,它仍然有效。我爲我的應用程序使用PHP-MYSQL。 我沒有任何網站,所以我將需要爲應用程序本身的答案。使用json保護http請求(android)
我正在使用Facebook的SDK與Android應用程序,所以我沒有任何密碼。我想確保用戶和用戶數據配置文件之間的聊天消息在被調用時提供。
我的問題是:
如何確保通話只應用內進行?
當有人試圖在瀏覽器中複製並粘貼代碼時,我該如何保護通話?
3.10秒後創建的消息有超時,所以相同的url和msg不能被重用。
我有http調用像http:/example.com/login=emailId;
get msgs:http:/example.com/getMsgs/user=uiniqueNo;
我已經提供了上述鏈接,因爲我在應用程序中使用它並且工作正常,但不安全。 請給我建議一些文件和過程。我已經檢查過這個鏈接Protect HTTP request from being called by others,但它不清楚。請給我建議任何具有上述要求的教程。在此先感謝。我真的很感謝幫助。
public class CustomizedListView extends Activity {
// All static variables
static final String URL = "http://example.com/getmsgs/userno=123";
// XML node keys
static final String KEY_SONG = "song"; // parent node
static final String KEY_ID = "id";
static final String KEY_TITLE = "title";
static final String KEY_ARTIST = "artist";
static final String KEY_DURATION = "duration";
static final String KEY_THUMB_URL = "thumb_url";
ListView list;
LazyAdapter adapter;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
ArrayList<HashMap<String, String>> songsList = new ArrayList<HashMap<String, String>>();
JSONObject json = JSONfunctions.getJSONfromURL(URL);
try {
JSONObject arr2 = json.getJSONObject("feed");
JSONArray arr = arr2.getJSONArray("entry");
for (int i = 0; i < arr.length(); i++) {
JSONObject e1 = arr.getJSONObject(i);
JSONArray arr3 = e1.getJSONArray("im:image");
JSONObject arr8 = e1.getJSONObject("im:name");
JSONObject arr10 = e1.getJSONObject("im:artist");
JSONObject e12 = arr3.getJSONObject(0);
// creating new HashMap
HashMap<String, String> map = new HashMap<String, String>();
map.put(KEY_THUMB_URL, e12.getString("label"));
map.put(KEY_ARTIST, arr8.getString("label"));
map.put(KEY_TITLE, arr10.getString("label"));
// adding HashList to ArrayList
songsList.add(map);
}
} catch (JSONException e) {
// Log.e("log_tag", "Error parsing data "+e.toString());
Toast.makeText(getBaseContext(),
"Network communication error!", 5).show();
}
list=(ListView)findViewById(R.id.list);
// Getting adapter by passing xml data ArrayList
adapter=new LazyAdapter(this, songsList);
list.setAdapter(adapter);
// Click event for single list row
list.setOnItemClickListener(new OnItemClickListener() {
@SuppressWarnings("unchecked")
@Override
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
HashMap<String, String> o = (HashMap<String, String>) list.getItemAtPosition(position);
Toast.makeText(CustomizedListView.this, "ID '" + o.get("KEY_TITLE") + "' was clicked.", Toast.LENGTH_SHORT).show();
}
});
}
}
在上面的代碼中任何人都可以猜到usersno但我怎麼保證,在應用程序和PHP服務器。所以,即使嗅探程序中沒有123被使用,並進行反向工程從apk文件獲取代碼該數據仍然是保護和加密應該在OS深哪些用戶不能打破,因此我可以在服務器PHP解密代碼,用戶將沒有辦法隨意輸入任何內容爲123
<?php
$strno=$_GET['strno'];
if (isset($strno))
{
$connect=mysql_connect("localhost","test","test") or die ('Connection error!!!');
mysql_select_db("test") or die ('Database error!!!');
$query=mysql_query("select sno FROM users where strno='$strno';");
while($row = mysql_fetch_assoc($query))
{
$jsonoutput='{"json":{
"msg_sub":"'.$row['msg_sub'].'",
}}';
}
}
echo trim($jsonoutput);
mysql_close($connect) or die ('Unable to close connection-error!!!');
}
?>
我注意到你有'http:// example.com/getmsgs/limit = 20/userno = 123'作爲你的api端點。你可以發佈在那裏運行的代碼嗎? – 1337holiday
我在上面,現在隨時都在。 –
也增加了php代碼。其簡化。 –