简体   繁体   English

我将Android应用程序与WAMP服务器连接的链接是什么?

[英]What is the link I put to connect my android app with my WAMP server?

I want to connect my android app to WAMP Server. 我想将我的Android应用程序连接到WAMP Server。 Following is the code: 以下是代码:

This is the code to create a new product and store it in the table. 这是创建新产品并将其存储在表中的代码。 NewProductActivity.java NewProductActivity.java

package com.chayan.chayanconnect;

import android.app.Activity;
import android.app.ProgressDialog;
import android.content.Intent;
import android.os.AsyncTask;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;

import org.apache.http.NameValuePair;
import org.apache.http.message.BasicNameValuePair;
import org.json.JSONException;
import org.json.JSONObject;

import java.util.ArrayList;
import java.util.List;

public class NewProductActivity extends Activity {


    // Progress Dialog
    private ProgressDialog pDialog;

    JSONParser jsonParser = new JSONParser();
    EditText inputName;
    EditText inputPrice;
    EditText inputDesc;

    // url to create new product
    private static String url_create_product = "http://192.168.0.1/create_product.php";

    // JSON Node names
    private static final String TAG_SUCCESS = "success";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_new_product);


        // Edit Text
        inputName = (EditText) findViewById(R.id.inputName);
        inputPrice = (EditText) findViewById(R.id.inputPrice);
        inputDesc = (EditText) findViewById(R.id.inputDesc);

        // Create button
        Button btnCreateProduct = (Button) findViewById(R.id.btnCreateProduct);

        // button click event
        btnCreateProduct.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View view) {
                // creating new product in background thread
                new CreateNewProduct().execute();
            }
        });
    }

    /**
     * Background Async Task to Create new product
     * */
    class CreateNewProduct extends AsyncTask<String, String, String> {

        /**
         * Before starting background thread Show Progress Dialog
         * */
        @Override
        protected void onPreExecute() {
            super.onPreExecute();

            pDialog = new ProgressDialog(NewProductActivity.this);
            pDialog.setMessage("Creating Product..");
            pDialog.setIndeterminate(false);
            pDialog.setCancelable(true);
            pDialog.show();
        }
        String name = inputName.getText().toString();
        String price = inputPrice.getText().toString();
        String description = inputDesc.getText().toString();
        /**
         * Creating product
         * */
        protected String doInBackground(String... args) {


            // Building Parameters
            List<NameValuePair> params = new ArrayList<NameValuePair>();
            params.add(new BasicNameValuePair("name", name));
            params.add(new BasicNameValuePair("price", price));
            params.add(new BasicNameValuePair("description", description));

            // getting JSON Object
            // Note that create product url accepts POST method
            JSONObject json = jsonParser.makeHttpRequest(url_create_product,
                    "POST", params);

            // check log cat fro response
            Log.d("Create Response", json.toString());

            // check for success tag
            try {
                int success = json.getInt(TAG_SUCCESS);

                if (success == 1) {
                    // successfully created product
                    Intent i = new Intent(getApplicationContext(), AllProductsActivity.class);
                    startActivity(i);

                    // closing this screen
                    finish();
                } else {
                    // failed to create product
                }
            } catch (JSONException e) {
                e.printStackTrace();
            }

            return null;
        }

        /**
         * After completing background task Dismiss the progress dialog
         * **/
        protected void onPostExecute(String file_url) {
            // dismiss the dialog once done
            pDialog.dismiss();
        }

    }
}

Please Help. 请帮忙。 Connection is not established. 未建立连接。

Try to insert the door of your server web, for example in my case it was: 192.168.1.11:80/file.php. 尝试插入服务器网络的门,例如在我的情况下为:192.168.1.11:80/file.php。

Then this is your local address, to connect you must be connected in the same LAN and be sure that your pc firewall doesn't block the connection, try to search a guide for you OS how to open firewall 然后,这是您的本地地址,要进行连接,必须将您连接在同一局域网中,并确保您的PC防火墙不会阻止连接,请尝试搜索操作系统指南,以了解如何打开防火墙

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 我如何将我的android设备(不是模拟器)连接到wamp服务器? - How can i connect my android device (not emulator) to wamp server? 通过 api 将我的 Android 应用程序连接到我本地主机上的服务器 - Connect my Android app trough an api to my server on my localhost 无法将我的 android 应用程序连接到本地主机服务器 - Unable to connect my android app to localhost server 当我链接到我的Web服务器上的PHP文件时,它将不会加载,但是当我链接到本地​​WAMP服务器上的文件时,它将完美地工作 - When I link to my PHP file on my webserver, it will not load, but when I link to it on local WAMP server it works perfectly 我需要在服务器上做什么才能与Android应用程序通信? - What to I need to do to on my server to communicate with an Android app? 为什么我需要使用“ localhost:8080”而不是“ localhost”来连接服务器WAMP? - Why do I need to use 'localhost:8080' instead of just 'localhost' to connect to my server WAMP? 如何在Android应用程序中从Wamp服务器数据库连接和检索数据? - How can I connect and retrieve data from wamp server database in Android app ? 如何将Android连接到WAMP服务器 - how to connect android to wamp server 如何将我的 WAMP 放到网上供他人访问? - How can I put my WAMP online for someone to access? 我如何让我的虚拟主机在线(wamp 3.2.3) - how i put my virtualhost online (wamp 3.2.3)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM