我正在使用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代码。其简化。 –