잠시 검색했지만 아직 해결책을 찾지 못했습니다. httpsost를 my php 파일에 보내서 myql 데이터베이스에 저장합니다. 하지만 내가 데이터베이스를 확인할 때 나는 빈 포스트를 본다. 엔트리가 삽입 된 것을 볼 수 있지만 값은 비어 있습니다. 내 PHP 코드를 확인하고 수동으로 URL을 정보로 핑 (ping)하면 데이터베이스에 저장됩니다. 내 logcat에 오류가 표시되지 않습니다.Httppost mysql이 비어 있습니다.
public class Add extends Activity implements View.OnClickListener
{
/** Called when the activity is first created. */
private Button add_btn;
EditText name;
EditText addy;
EditText hours;
EditText desc;
TextView error;
List<NameValuePair> nameValuePairs;
InputStream is;
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.add);
add_btn = (Button)findViewById(R.id.add_btn);
add_btn.setOnClickListener((OnClickListener) this);
name = (EditText)findViewById(R.id.action_name);
addy = (EditText)findViewById(R.id.action_addy);
hours = (EditText)findViewById(R.id.action_hours);
desc = (EditText)findViewById(R.id.action_desc);
error = (TextView)findViewById(R.id.error_text);
}
public boolean onCreateOptionsMenu(Menu menu)
{
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.mapnav, menu);
return true;
}
public void onClick(View v)
{
if(v == add_btn)
{
if(name.getText().length()== 0)
{
error.setText("You Must enter a bussiness name.");
}
else if(desc.getText().length()== 0)
{
error.setText("Please enter a short description. I.E. Beer Bar or Dance Club");
}
else
{
new Connect().execute();
name.setText("");
addy.setText("");
hours.setText("");
desc.setText("");
}
}
}
private class Connect extends AsyncTask<Void, Void, Void>
{
@Override
protected void onPreExecute()
{
super.onPreExecute();
}
@Override
protected Void doInBackground(Void... params)
{
try
{
String a = name.getText().toString().trim();
String b = addy.getText().toString().trim();
String c = hours.getText().toString().trim();
String d = desc.getText().toString().trim();
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new
HttpPost("http://www.website.com/phpfile.php");
nameValuePairs = new ArrayList<NameValuePair>(4);
nameValuePairs.add(new BasicNameValuePair("bname", a));
nameValuePairs.add(new BasicNameValuePair("baddy", b));
nameValuePairs.add(new BasicNameValuePair("bhours", c));
nameValuePairs.add(new BasicNameValuePair("bdesc", d));
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs,HTTP.UTF_16));
HttpResponse response = httpclient.execute(httppost);
HttpEntity entity = response.getEntity();
is = entity.getContent();
Log.e("Server Response: ", " " + response);
}
catch(Exception e)
{
Log.e("log_tag", "Error in http connection "+e.toString());
//error.setText("Connection error");
}
return null;
}
}
}
서버가 UTF_16으로 인코딩 된 게시 본문 매개 변수를 필요로합니까? 일반적으로 UTF_8입니다. 믿을 수도 있고 아닐 수도 있습니다. 수정 : 내가 문제를 발견했습니다, 아래에 게시 된 답변을 확인하십시오. – Ryan
우수 .. 그게 해결책이었습니다. 고마워, 나는 몇 시간 동안 수색을 해왔다. – Jayce