如何从loopj获取android-async-http的Throwable(错误)?(How do I get the Throwable (error) at android-async-http from loopj?)
我正在使用来自LoopJ(https://github.com/loopj/android-async-http)的(我猜)颇受欢迎的库来发出GET和POST请求。 一切正常,但是当涉及到cookie处理时,我遇到了一些错误。 有时,我的应用程序中的POST-Login请求无故失败。 在这种情况下,正确调用POST请求的onFailure方法:
@Override public void onFailure(Throwable error, String content) { Log.e("custom onFailure POST", error.getMessage()); cb.onTaskComplete("LOGIN_FAILED"); }
奇怪的是,“Throwable error”和“String content”都是NULL对象。 这使得很难分析将用户登录到我的应用程序的问题。 有人能告诉我,如何获得失败的根源? 是否还有其他方法可以实现从请求中获得更好的故障转发?
I am using the (I guess) quite popular library from LoopJ (https://github.com/loopj/android-async-http) to make GET and POST requests. Everything if working fine, but when it comes to cookie-handling I got some errors. Occasionally the POST-Login request in my app fails for no reason. In that case, the onFailure-method of the POST request is called correctly:
@Override public void onFailure(Throwable error, String content) { Log.e("custom onFailure POST", error.getMessage()); cb.onTaskComplete("LOGIN_FAILED"); }
The strange thing is, that both "Throwable error" and "String content" are NULL-objects. That makes it really hard to analyze to problem of logging the user in into my app. Can someone tell me, how to get the source of the failure? Are there other methods I can implement to get a better fail-repost from the request?
原文:https://stackoverflow.com/questions/14462527
最满意答案
尝试:
echo 'export PATH="$PATH:$GOPATH/bin"' >> ~/.profile
POSIX类shell中的单引号字符串(例如
bash
)将其内容视为文字 ,这就是您想要的。在这里使用双引号字符串的唯一原因是预先选择性地扩展变量引用 - 这在您的情况下不适用。
也就是说,这是一个例子:
$ echo "Honey, I'm \"$USER\" and I'm \$HOME." Honey, I'm "jdoe" and I'm $HOME.
反斜杠转义用于转义应被视为文字的嵌入式
"
和$
实例"
。
至于你试过的:
"export PATH="$PATH:$GOPATH/bin""
实际上是一个字符串连接 ,由3个独立的字符串组成:
"export PATH="
,作为双引号字符串, 不包含$
-prefixed插值元素,扩展为文字export PATH=
$PATH:$GOPATH/bin
,作为一个不带引号的字符串,受到额外的shell扩展 ,这不仅涉及将变量$PATH
和$GOPATH
到它们各自的值,还应用了字拆分和路径名扩展(globbing) 。""
,相当于空字符串,实际上被忽略了。请注意类似POSIX的shell如何通过将字符串(不带引号或单引号或双引号) 直接放在另一个上来组成更大的字符串(连接字符串)。
Try:
echo 'export PATH="$PATH:$GOPATH/bin"' >> ~/.profile
Single-quoted strings in POSIX-like shells (such as
bash
) treat their content as literals, which is what you want here.The only reason to use a double-quoted string here would be to selectively expand variable references up front - which doesn't apply in your case.
That said, here's an example:
$ echo "Honey, I'm \"$USER\" and I'm \$HOME." Honey, I'm "jdoe" and I'm $HOME.
Backslash-escaping is used to escape embedded
"
and$
instances that should be treated as literals.
As for what you tried:
"export PATH="$PATH:$GOPATH/bin""
is actually a string concatentation, composed of 3 separate strings:
"export PATH="
, which, as a double-quoted string that happens not to contains$
-prefixed interpolation elements, expands to literalexport PATH=
$PATH:$GOPATH/bin
, which, as an unquoted string, is subject to additional shell expansions, which not only involves expanding variables$PATH
and$GOPATH
to their respective values, but also applies word-splitting and pathname expansion (globbing).""
, which amounts to the empty string and is effectively ignored.Note how POSIX-like shells allow you to compose larger strings (concatenate strings) by placing strings - unquoted or single-quoted or double-quoted - directly next to one another.
相关问答
更多-
您可以使用setLocal enableDelayedExpansion使您的变量按预期展开。 请尝试以下方法: setLocal enableDelayedExpansion set BuildRoot=d:\ set OutDir=%Tmp% call :GenerateBaseLine "Build" goto :eof :GenerateBaseLine call dir /s /b /A-D !%1Root! > %OutDir%\%1Baseline.txt echo "wrote dir / ...
-
这是shell和环境变量之间的区别。 这里, test=4 python test.py 将test=4传递给python的环境,因此您将在脚本中获得变量test 。 而 test=4; python test.py 创建一个只在当前shell会话中可用的shell变量(这就是你从shell获取值的原因),即不会传播到环境中。 要创建一个变量环境变量,以便所有子进程继承变量,即在进程环境中使变量可用,任何POSIX shell上的常用方法是export变量: export test=4; python ...
-
rails 3,如何在Settings.yml文件中使用ENV config vars?(rails 3, how use an ENV config vars in a Settings.yml file?)[2022-03-19]
使用如下: - default: cv1: Foo cv2: <%= ENV['FOOVAR'] %> use following:- default: cv1: Foo cv2: <%= ENV['FOOVAR'] %> -
这是答案...... 它工作正常。 $(ENV_VAR_NAME)不是%ENV_VAR_NAME% (我觉得自己像个白痴。) Here's the answer... it works fine. $(ENV_VAR_NAME) not %ENV_VAR_NAME% (I feel like an idiot. )
-
Ansible vars使用查找(Ansible vars using lookups)[2021-02-15]
如果前面的表达式的值是空字符串(如未定义的环境变量的情况下),那么可以使用带有选项的default过滤器来触发它: - APP_NAME: "{{ lookup('env', 'customName') | default(lookup('env', 'name'), true) | mandatory }}" You can use the default filter with an option to trigger it if the value of the preceding expressi ... -
您可以使用以下语法引用先前定义的环境变量: env: - name: LOG_LEVEL valueFrom: configMapKeyRef: name: my.configmap key: log.level - name: JAVA_OPTIONS value: -Dswarm.logging=$(LOG_LEVEL) 不知道这会启动Java选项,但是,我通常编辑图像,并调用一个entrypoint.sh文件,其中一些逻辑将存在,但它值得我尝试一个尝试。 Yo ...
-
您可以利用以下功能: System.get_env/1 。 You could leverage the following function: System.get_env/1.
-
使用zsh中的.env(dotenv)文件从Ruby访问环境变量(Accessing environment vars from Ruby using a .env (dotenv) file in zsh)[2023-08-01]
与dotenv文档中所述的dotenv ,您实际上需要使用.env文件中的export关键字来使参数可用于环境,例如 export FOO=foo 唯一的例外是,如果参数已经是一个环境变量。 例如,如果它已经在~/.zshrc导出,或者它已经是开始时获得的zsh环境的一部分(例如PATH或HOME )。 当更改到目录时,所有dotenv都会自动获取任何.env文件。 没有额外的“魔法”。 这意味着.env需要是一个有效的zsh脚本,并且其内容在当前shell会话的上下文中运行(基本上就像手动键入它一样)。 ... -
尝试: echo 'export PATH="$PATH:$GOPATH/bin"' >> ~/.profile POSIX类shell中的单引号字符串(例如bash )将其内容视为文字 ,这就是您想要的。 在这里使用双引号字符串的唯一原因是预先选择性地扩展变量引用 - 这在您的情况下不适用。 也就是说,这是一个例子: $ echo "Honey, I'm \"$USER\" and I'm \$HOME." Honey, I'm "jdoe" and I'm $HOME. 反斜杠转义用于转义应被视为文 ...
-
试试Shell :: Source 。 Try Shell::Source.