标签: http-post

php if elseif语句问题

我有一个非常简单的PHP程序,我正在为我的计算机科学课程工作,但我遇到了一些麻烦.

<?php
$numOfCards = '50'; //$_POST['numOfCards'];
$totalCost = 0.00;

if (numOfCards == '20')
{
$totalCost = $numOfCards*3.00;
}
else if (numOfCards == '50')
{
$totalCost = $numOfCards*2.50;
}
else
{
$totalCost = $numOfCards*2.00;
}

echo "<p>TOTAL COST FOR ".$numOfCards." CARDS: $".$totalCost."</p>";
?>
Run Code Online (Sandbox Code Playgroud)

正如您所看到的,我最初从发布数据中获取了$ numOfCards值,但已将其设置为50以证明一点.问题是这个代码应该转到else if语句,而是转到else语句.这导致totalCosts等于100美元而不是125美元.

有谁知道我做错了什么?谢谢

php if-statement http-post

1
推荐指数
1
解决办法
492
查看次数

使用HTTP Post将数据从excel发送到服务器

如何使用HTTP Post从excel发送数据到服务器?

可以说URL是:http:// testingHttpPost /

我想从单元格A2和B2发送数据.我如何在VBA中完成这项工作?

提前致谢

sql-server asp.net-mvc vba http-post

1
推荐指数
1
解决办法
6134
查看次数

使用JSON执行HttpPost时没有响应

我创建了一个提交按钮,我在其中调用方法"call2",其中包含使用JSON执行HttpPost的代码

      final Button submit = (Button) findViewById(R.id.Button03);
      submit.setOnClickListener(new View.OnClickListener() {
          public void onClick(View v)
          {

            // Perform action on click
             Toast.makeText(display.this,"You have selected to submit data of students",Toast.LENGTH_SHORT).show();
             call2();           
          }

      });      

   } //OnCreate method ends

  After that I have my call2 method as follows:

       public String call2()
        {
      String result="";
      HttpParams httpParams = new BasicHttpParams();
      HttpPost httppost = new HttpPost("http://10.0.2.2/enterdata/Service1.asmx");
          HttpClient client = new DefaultHttpClient(httpParams);

       try
     {


     JSONArray jsArray = new JSONArray(items2);
     jsArray.put(items2);   

     int TIMEOUT_MILLISEC = 10000;  // = 10 …
Run Code Online (Sandbox Code Playgroud)

android json web-services http-post

1
推荐指数
1
解决办法
5636
查看次数

使用HttpClient.PostAsJsonAsync发布标量数据类型

我正在使用HttpClient调用ASP .Net Web API并成功调用操作.此外,我也可以将自定义对象发布到操作中.

现在我面临的问题是,无法发布标量数据类型,如Integer,String等...

下面是我的控制器和调用操作的应用程序代码

//测试调用的应用程序

[Test]
        public void RemoveCategory()
        {
            HttpClient client = new HttpClient();

            HttpRequestMessage request = new HttpRequestMessage();

            HttpResponseMessage response = client.PostAsJsonAsync<string>("http://localhost:49931/api/Supplier/RemoveCategory/", "9").Result;

            Console.WriteLine(response.Content.ReadAsStringAsync().Result);
        }
Run Code Online (Sandbox Code Playgroud)

// Web API中的控制器和操作

public class SupplierController : ApiController
   {
    NorthwindEntities context = new NorthwindEntities();

    [HttpPost]
    public HttpResponseMessage RemoveCategory(string CategoryID)
    {
    try
    {
    int CatId= Convert.ToInt32(CategoryID);
    var category = context.Categories.Where(c => c.CategoryID == CatId).FirstOrDefault();
    if (category != null)
    {
    context.Categories.DeleteObject(category);
    context.SaveChanges();
    return Request.CreateResponse(HttpStatusCode.OK, "Delete successfully CategoryID = "     +     CategoryID);
    }
    else …
Run Code Online (Sandbox Code Playgroud)

using http-post dotnet-httpclient

1
推荐指数
1
解决办法
2958
查看次数

Http Post获取Windows Phone 8的响应错误

我正在重新发布我的原始帖子(Windows Phone 8的Http Post)中的第二个问题,因为我的主要问题是答案.

这是我在@Hunter McMillen的帮助下更新的代码.我现在正试图从服务器获取responseCallback.问题是GetResponseCallback => (HttpWebResponse)httpWebRequest.EndGetResponse(GetResponseCallback)第二个使用语句中的行,它正在显示

An exception of type 'System.Net.WebException' occurred in System.Windows.ni.dll but was not handled in user code

If there is a handler for this exception, the program may be safely continued.
Run Code Online (Sandbox Code Playgroud)

在我使用第一个示例之前发生此错误.有谁知道如何解决这个问题?

  private static async void HttpPostData(){
            string url = "http://www.mytunnel.com/api/purchases";
            HttpWebRequest httpWebRequest = (HttpWebRequest)WebRequest.Create(url);
            httpWebRequest.ContentType = "text/plain";
            //httpWebRequest.ContentType = "application/x-www-form-urlencoded";
            httpWebRequest.AllowWriteStreamBuffering = true;
            httpWebRequest.Method = "POST";
            //httpWebRequest.ContentLength = jsonAsBytes.Length;

        try{
            using (var stream = await Task.Factory.FromAsync<Stream>(httpWebRequest.BeginGetRequestStream, httpWebRequest.EndGetRequestStream, null))
            { …
Run Code Online (Sandbox Code Playgroud)

c# sdk http-post windows-phone

1
推荐指数
1
解决办法
5123
查看次数

如何在从servlet过滤器执行HTTP重定向时保留请求主体

我有一个部署在2台主机上的Java Web应用程序,前面是servlet过滤器.我在一台主机上向应用程序发送了一个POST请求,该请求被过滤器拦截并重定向到另一台主机:

public void doFilter (ServletRequest request, ServletResponse response,
       FilterChain filterChain)
{
    ...
    if(shouldRedirect) {
        httpResponse.sendRedirect(redirectLocation);
    }
}
Run Code Online (Sandbox Code Playgroud)

在第二台机器上,请求传递过滤器,并由Resource类中的REST API处理.

@POST
public Response handleRequest(InputStream stream)
{
    ...
}
Run Code Online (Sandbox Code Playgroud)

stream对象作为POST请求正文的一部分发送.重定向后,请求正文不会被发送并且stream为空.如何在重定向后保留请求正文(或至少这部分内容)?

谢谢.

java http-post servlet-filters

1
推荐指数
1
解决办法
2672
查看次数

使用http post params android进行基本身份验证

我通过传递用户名和密码进行基本身份验证,然后使用BasicNameValuePair发送post params来获取服务的响应.

我的方法:

public StringBuilder callServiceHttpPost(String userName, String password, String type)
    {

        // Create a new HttpClient and Post Header
        HttpClient httpclient = new DefaultHttpClient();
        HttpPost httppost = new HttpPost(WEBSERVICE + type);



        HttpResponse response = null;

        StringBuilder total = new StringBuilder();

        try {

            URL url = new URL(WEBSERVICE + type);

            /*String base64EncodedCredentials = Base64.encodeToString((userName
                    + ":" + password).getBytes(), Base64.URL_SAFE
                    | Base64.NO_WRAP);*/

            String base64EncodedCredentials = "Basic " + Base64.encodeToString(
                    (userName + ":" + password).getBytes(),
                    Base64.NO_WRAP);


            httppost.setHeader("Authorization", base64EncodedCredentials);

            // Add …
Run Code Online (Sandbox Code Playgroud)

android http-post basic-authentication

1
推荐指数
1
解决办法
1万
查看次数

Restkit映射问题 - 将新创建的托管对象发布到服务器

我正在尝试使用rest kit将新的托管对象发布到服务器,但我不知道我做错了什么.我得到如下例外情况:

由于未捕获的异常'NSInvalidArgumentException'而终止应用程序,原因:' RKRequestDescriptor对象必须使用目标类为的映射进行初始化NSMutableDictionary,得到'用户'(请参阅参考资料[RKObjectMapping requestMapping])'

我正在寻找像这样的堆栈溢出帖子的解决方案 这是我从MappingProvider类的实体映射方法:

+(RKMapping *)usersMapping
{
RKEntityMapping *mapping = [RKEntityMapping mappingForEntityForName:@"Users" inManagedObjectStore:[[DateModel sharedDataModel]objectStore]];

[mapping addAttributeMappingsFromDictionary:@{
                                              @"id": @"user_id",
                                              @"address1": @"address1",
                                              @"address2": @"address2",
                                              @"created_at":@"created_at",
                                              @"updated_at": @"updated_at",
                                              @"email": @"email",
                                              @"name":@"name",
                                              @"password_digest": @"password_digest",
                                              @"phone_no": @"phone_no",
                                              @"postcode":@"postcode",
                                              @"remember_token":@"remember_token",
                                              @"user_type": @"user_type",
                                              @"apns_token":@"apns_token"
                                              }
 ];

[mapping addRelationshipMappingWithSourceKeyPath:@"admins" mapping:[MappingProvider adminsMapping]];
[mapping addRelationshipMappingWithSourceKeyPath:@"carers" mapping:[MappingProvider carersMapping]];
[mapping addRelationshipMappingWithSourceKeyPath:@"customers" mapping:[MappingProvider customersMapping]];
[mapping addRelationshipMappingWithSourceKeyPath:@"userWearers" mapping:[MappingProvider customersMapping]];

return mapping;
Run Code Online (Sandbox Code Playgroud)

这是用户填写所有文本字段并单击注册按钮时调用的方法:

-(void)registerUser
{RKResponseDescriptor *userResponseDescriptor = [RKResponseDescriptor responseDescriptorWithMapping:[MappingProvider usersMapping] method:RKRequestMethodPOST pathPattern:nil keyPath:nil statusCodes:RKStatusCodeIndexSetForClass(RKStatusCodeClassSuccessful)];
//here …
Run Code Online (Sandbox Code Playgroud)

core-data http-post restkit restkit-0.20

1
推荐指数
1
解决办法
1044
查看次数

如何在node.js的帮助下发送xml post params

尝试通过节点js将XML数据发布到以下网址:-

var request = require("request");
var utf8 = require('utf8');



var abc = '<ENVELOPE><HEADER><TALLYREQUEST>Export Data</TALLYREQUEST></HEADER><BODY><EXPORTDATA><REQUESTDESC><REPORTNAME>Stock Summary</REPORTNAME><STATICVARIABLES><EXPLODEFLAG>Yes</EXPLODEFLAG><SVEXPORTFORMAT>$$SysName:XML</SVEXPORTFORMAT><ACCOUNTTYPE>All Inventory Masters</ACCOUNTTYPE></STATICVARIABLES></REQUESTDESC></EXPORTDATA></BODY></ENVELOPE>';

request.post({
    url:"http://192.168.1.148",
    port: 9000,
    method:"POST",
    headers:{
        'Content-Type': 'application/xml',
    },
     body: abc
},
function(error, response, body){
    console.log(response.statusCode);
    console.log(body);
    console.log(error);
});
Run Code Online (Sandbox Code Playgroud)

但是解释器显示以下错误:-

console.log(response.statusCode);
                    ^
TypeError: Cannot read property 'statusCode' of undefined
at Request._callback (C:\Users\bliscar\prog10.js:18:25)
at self.callback (C:\Users\bliscar\node_modules\request\request.js:198:22)
at Request.emit (events.js:107:17)
at Request.onRequestError (C:\Users\bliscar\node_modules\request\request.js:
Run Code Online (Sandbox Code Playgroud)

861:8)在ClientRequest.emit(events.js:107:17)在Socket.socketErrorListener(_http_client.js:271:9)在Socket.emit(events.js:107:17)在net.js:459: 14在process._tickCallback(node.js:355:11)

无法解决问题所在。请帮忙解决。

xml post http-post node.js

1
推荐指数
1
解决办法
6076
查看次数

HTTP RESTful Web服务注销:哪个是正确的或更好的做法 - POST还是DELETE?

正如在"RESTful"设置中使用HTTP方法登录和注销操作所接受的答案所述,建议在RESTful Web服务(例如/webservice/login/)中使用HTTP POST(= create)进行登录.POST既不是幂等的也不是安全的(http://restcookbook.com/HTTP%20Methods/idempotency/).

但是如何注销(例如/ webservice/logout /).我应该使用POST还是DELETE?

DELETE是幂等的 - 无论服务器上是否存在会话(或其他),它都会被删除,并且来自网络服务器的答案没有任何进一步的内容.这对我来说有点自然.

POST不是幂等的,类似问题的一些海报建议POST用于REST注销.我可以想到两个可能的原因:

  1. 如果会话不存在,服务器可能会返回404 - 否则成功答案(两种答案)

  2. 注销可以触发例如包含用户等的注销信息的数据库更新,因此注销操作不是幂等的

那么哪种HTTP方法更适合注销 - POST或DELETE?

rest http http-post http-delete

1
推荐指数
1
解决办法
3309
查看次数